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

Use in keyword for enums #14084

Closed
pocesar opened this issue Feb 15, 2017 · 1 comment
Closed

Use in keyword for enums #14084

pocesar opened this issue Feb 15, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@pocesar
Copy link

pocesar commented Feb 15, 2017

Although enums are both numbers and strings, it's not possible to use a type like this:

enum Values {
  A, B, C
}

type ValuesConstraint = {
  [index: Values]: string; // An index signature parameter type must be 'string' or 'number'
}

const Mapped: ValuesConstraint = {
   [Values.A]: 'Alpha',
   [Values.B]: 'Beta',
   [Values.C]: 'Gamma'
}

const f = Mapped[Values.C] // f: any

Tried to use in as in [index in Values] but it says Type 'Values' is not assignable to type 'string'. Trying to use a type ValuesType = Values.A | Values.B | Values.C also doesn't work, is there any workaround?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 15, 2017
@RyanCavanaugh
Copy link
Member

See #2491, #13042

@pocesar pocesar closed this as completed Feb 16, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants