Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index which's key's type is number can accept string keys #21179

Closed
Lcng opened this issue Jan 14, 2018 · 1 comment
Closed

Index which's key's type is number can accept string keys #21179

Lcng opened this issue Jan 14, 2018 · 1 comment
Labels
Question An issue which isn't directly actionable in code

Comments

@Lcng
Copy link

Lcng commented Jan 14, 2018

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?

@Lcng Lcng changed the title Index Bug? Index which's key's type is number can accept string keys Jan 14, 2018
@yortus
Copy link
Contributor

yortus commented Jan 15, 2018

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.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jan 17, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants