I am trying to type objects that would look like :
{
name: "toto",
index: [ 1, 2, 3],
foo: [ "foo1", foo2", "foo3"],
bar: [ "bar1", "bar2","bar3"]
}
I know for sure that I will have the name and index attributes, however I don't know whether I will have one or x "foo" attributes.
I tried the following interface:
export interface MyInterface {
name: string;
index: Array<number>;
[seriesname: string]: Array<string>;
}
The error is thrown for the row:
name: string;
Property 'name' of type 'string' is not assignable to string index type 'string[]'.ts(2411)
I seems to me that all my attributes MUST be compatible with the dictionary I described with the row:
[seriesname: string]: Array<string>;
Which means I cannot type my object like this. Is there a way to do it ? (I don't want to modify the object, as I receive it from another application.)