I have this data:
{
name1: 'name',
name2: [{},{},{}],
name3: true,
}
And I want to type it. Name1, name2, and name3 are created automatically, and may have other names, but the structure is like this.
How do I type this?
I tried doing smth like this:
export type data = {
[key: string]: boolean;
[key: string]: number;
[key: string]: Array<MachineMapping>;
};
But now I'm getting:
Duplicate index signature for type 'string'.
How do I handle this?
CodePudding user response:
You can use a union.
export type data = {
[key: string]: boolean | number | Array<MachineMapping>;
};