I recently delved into the Microsoft Typescript Handbook and found myself intrigued by the indexable types chapter. To gain a deeper understanding, I decided to experiment with the code provided. Strangely enough, upon running this particular piece of code, I was surprised that it did not prompt any errors:
interface NumberDictionary {
[index: number]: number;
length: number;
name: number;
}
// 'x' is not a number, 's' is not a number
let foo: NumberDictionary = { x: 's', length: 2, name: 3 };
Oddly enough, upon removing the initial line in the interface, an error did arise indicating that 'x' was not part of the declared interface.