Closed
Description
TypeScript Version: 2.8.3-insiders.20180407
(Also in the Playground)
Search Terms: index signature
Code
let x: string = "x";
x = 1; // As expected, this line doesn't compile
interface Obj {
[id: string]: boolean;
}
let y: Obj = {};
y["okay"] = true;
y[123] = false; // The id is set to string, why does it compiles?
Expected behavior:
The last line of the code, I would expect to have TypeScript to say the same error as the second line. The error should say that the index must be a string.
Actual behavior:
The code compiles without error even if it is mentioned that only string must be accepted.
Related Issues: Couldn't find.