How to declare this nested dynamic object in TypeScript?
{
foo: "bar",
["some"]: {
innerKey: "bar",
},
["other"]: {
innerKey: "bar",
},
}
Using this doesn’t work, I get an error because of foo
.
interface NestedObject {
foo: string;
[key: string]: {
innerKey: string;
};
}
Property 'foo' of type 'string' is not assignable to 'string' index type '{ innerKey: string; }'.ts(2411)