Skip to content

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

Description

@nevir

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]

Activity

  1. RyanCavanaugh commented on Jun 29, 2017

    @RyanCavanaugh
    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.
    
  2. nevir commented on Jun 29, 2017

    @nevir
    Author

    Ryan Cavanaugh (@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

  3. amitbeck commented on Jun 30, 2017

    @amitbeck

    Ryan Cavanaugh (@RyanCavanaugh) but is it ever going to be supported/legal?

  4. nevir commented on Jun 30, 2017

    @nevir
    Author

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

  5. amitbeck commented on Jun 30, 2017

    @amitbeck

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

  6. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions