TypeScript Version: 4.1.0-beta
Search Terms: string assignable index signature number
Code
interface NumberIndexable {
[index: number]: string;
}
function setValueAtIndex(object: NumberIndexable, index: number, value: string) {
object[index] = value;
}
setValueAtIndex({}, 0, 'test'); // works fine
setValueAtIndex('oops', 0, 'test'); // runtime error
Expected behavior:
Second call to setValueAtIndex should raise a compiler error.
Actual behavior:
No compiler error is raised, which results in a runtime error because string indeces are read-only.
Playground Link: Playground
TypeScript Version: 4.1.0-beta
Search Terms: string assignable index signature number
Code
Expected behavior:
Second call to setValueAtIndex should raise a compiler error.
Actual behavior:
No compiler error is raised, which results in a runtime error because string indeces are read-only.
Playground Link: Playground