Skip to content

Don't show string literals as completion options for string enums #16851

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

Closed
rokoroku opened this issue Jun 30, 2017 · 0 comments
Closed

Don't show string literals as completion options for string enums #16851

rokoroku opened this issue Jun 30, 2017 · 0 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rokoroku
Copy link

rokoroku commented Jun 30, 2017

TypeScript Version: 2.4.1

Code

const enum StringEnumType {
  STATUS_PENDING = 'PENDING',
  STATUS_COMPLETED = 'COMPLETED',
}

function aFunction(type: StringEnumType) { /* ... */ }

aFunction(StringEnumType.STATUS_PENDING); // OK
aFunction('PENDING');  // Error:  [ts] 'Argument of type '"PENDING"' is not assignable to parameter of type 'StringEnumType'.

2017-06-30 1 49 54

Expected behavior:

  • No error or no suggestion.

Actual behavior:

  • TS's suggestion shows the string values of the enums, but we cannot use the string values as it is.
 [ts] 'Argument of type '"PENDING"' is not assignable to parameter of type 'StringEnumType'.
@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug Bug A bug in TypeScript and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Jun 30, 2017
@RyanCavanaugh RyanCavanaugh changed the title String Enums' values are indexed, but cannot use as it is Don't show string literals as completion options for string enums Jun 30, 2017
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.5 milestone Jun 30, 2017
@ghost ghost closed this as completed in #18288 Sep 7, 2017
@ghost ghost added the Fixed A PR has been merged for this issue label Sep 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants