You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Index which's key's type is number can accept string keys #21179
When I declare an index like this:
let index: {[index: number]: string} = {};
Then I can add a member to the index like this:
index['3s'] = 3;
The type of the key '3s' is string. But this works. Is this a bug?
JavaScript objects coerce numeric indices to strings behind the scenes, leading to some modeling challenges for TypeScript. See some of the related issues for further explanation: #17191, #13715, #12425.
When I declare an index like this:
let index: {[index: number]: string} = {};
Then I can add a member to the index like this:
index['3s'] = 3;
The type of the key '3s' is string. But this works. Is this a bug?