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

Simple String union can be compared against the wrong string values #10409

Closed
AlexGalays opened this issue Aug 18, 2016 · 3 comments
Closed

Simple String union can be compared against the wrong string values #10409

AlexGalays opened this issue Aug 18, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@AlexGalays
Copy link

TypeScript Version: 2.0.0

Code

type Role = 'admin' | 'user'

const role: Role = 'admin'

if (role === '&!?# completelyrandom') {
   console.log(role)
}

Expected behavior:
I would expect simple if/ternary statements to be the idiomatic way to "type guard" string enums, but it doesn't do anything at compile time.

Actual behavior:
No error

@ahejlsberg
Copy link
Member

This has the expected behavior in the current nightly build.

@AlexGalays
Copy link
Author

Ok thanks, will update my beta version.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Aug 18, 2016
@DanielRosenwasser
Copy link
Member

Duplicate of #6149.

@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

3 participants