I would like to create an interface for an object that has a certain type for a specific named property and a different type for all other properties.
How would I write a definition for foo
below?
let foo = {
size: 3,
a: 'foo',
b: 'bar',
c: 'baz'
}
This would be my intuitive approach:
interface Foo {
size: number;
[name: string]: string;
}
However, TypeScript tries to apply the general definition to the specific definition and triggers the following error:
error TS2411: Property 'size' of type 'number' is not assignable to string index type 'string'.