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

Unable to use numeric enums as keys of a map #16842

Closed
nevir opened this issue Jun 29, 2017 · 5 comments
Closed

Unable to use numeric enums as keys of a map #16842

nevir opened this issue Jun 29, 2017 · 5 comments

Comments

@nevir
Copy link

nevir commented Jun 29, 2017

This appears to be a regression of #2491 (& #12425?)

TypeScript Version: 2.4.1

Code

Expected that this snippet does not produce errors, but it does:

enum Things { ONE, TWO }
// Error: Type 'Things' is not assignable to type 'string'. 
type ThingMap = {[TKey in Things]: boolean};

[Playground]

@RyanCavanaugh
Copy link
Member

What version did this work in? As far as I can tell this has never been legal

=== latest ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                         ~~~~~~
  TS2322: Type 'Things' is not assignable to type 'string'.
=== 2.3 ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                         ~~~~~~
  TS2322: Type 'Things' is not assignable to type 'string'.
=== 2.2 ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                         ~~~~~~
  TS2322: Type 'Things' is not assignable to type 'string'.
=== 2.1 ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                         ~~~~~~
  TS2322: Type 'Things' is not assignable to type 'string'.
=== 2.0 ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                ~~~~~~~~~~~~~~~~
  TS1170: A computed property name in a type literal must directly refer to a built-in symbol.

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                ~~~~~~~~~~~~~~~~
  TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                 ~~~~
  TS2304: Cannot find name 'TKey'.
=== 1.8 ===

clipboard.ts:3 type ThingMap = {[TKey in Things]: boolean}
                                ~~~~~~~~~~~~~~~~
  TS1170: A computed property name in a type literal must directly refer to a built-in symbol.

@nevir
Copy link
Author

nevir commented Jun 29, 2017

@RyanCavanaugh doh, sorry! I misread #2491 (comment) (and the followup comment) as if it was supported

I think we can probably close this as a dupe of #13042

@nevir nevir closed this as completed Jun 29, 2017
@amitbeck
Copy link

@RyanCavanaugh but is it ever going to be supported/legal?

@nevir
Copy link
Author

nevir commented Jun 30, 2017

@amitbeck it looks like it's on the roadmap: #13042 (comment)

@amitbeck
Copy link

@nevir I know, I've commented on that exact issue :) Didn't see the milestone change, thanks for reminding me.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants