-
-
Notifications
You must be signed in to change notification settings - Fork 79
Description
I wasn't sure how to phrase this error because in the past I've been very surprised to see that when defining a table's configuration you were asked to put in a object/dictionary but with numeric keys. Since upgrading to the most recently typed version of Table I wrote the following code:
const config: TableUserConfig = {
columns: [
{ width: 30, alignment: "left" },
{ width: 5, alignment: "center" },
{ width: 60, alignment: "left" },
],
};
console.log(table([["Name", "Version", "Description"], ...data], config));There were no type error but then I got a runtime error about an invalid configuration. I investigated and sure enough the typing depends on being Indexable and here's a code snippet of two test data structures sitting next to your Indexable:
export declare type Indexable<T> = {
readonly [index: number]: T;
};
const t1: Indexable<{test: string}> = [{test: "foo"}, {test: "bar"}];
const t2: Indexable<{test: string}> = { 1: {test: "foo"}, 2:{test: "bar"}};Neither has a typing error and therefore one of two things must be true:
- The type is unnecessarily permissive and you should be required to use object syntax but use numeric keys
- The run time checker is objecting to a type which should be fine
I must say the array syntax feel MUCH more natural than what can actually be used today at run time but either way one of the two really must change.