After defining this interface:
interface Thing1 {
[key: string]: string;
x: number;
}
During compilation in Typescript, an error is thrown stating "TS2411: Property 'x' of type number is not assignable to string index type 'string'."
While this error seems reasonable, when using an object literal as the indexed type value like:
interface Foo {}
interface Thing2 {
[key: string]: Foo;
foo: number;
}
Surprisingly, there is no error reported, even though number
and Foo
are different types.
Do you have any insights into why this inconsistency occurs?
Note: This was tested on Typescript 2.1.5