-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
enable type guards over string literal types #6028
Comments
Thanks for filing @Aleksey-Bykov! |
Is this no longer intended for TypeScript 1.8? |
I predict that'll be going in for 2.0. We're still working on the core functionality of string literal types, and how we want things to flow throughout the type system. If we do that right, this will be much easier and might enable much more interesting features down the road. |
@DanielRosenwasser is there an issue/set of issues to track about the type system work? |
what are the more exciting features? |
@Aleksey-Bykov basically the idea that you'd be able to not only narrow from strings to string literals, but you'd be able to use them as tags, as discussed in #1003. |
good, that is what this issue is about, I thought there might be more to that |
Not sure if its listed anywhere, but i think this should show an error: (Hopefully in the IDE) // declare
type options = 'option1' | 'option2';
interface A {
possibleOptions: options;
}
/// use (given class B that implements interface A)
var x = new B();
if (x.possibleOptions === 'option3') {
// there is no way of getting here is all possible values are either 'option1' or 'option2', should error
} |
Can we say that this has been fixed by #9163? |
yes, thanks
|
Now that the string literal types #5185 are merged in, the type guards based on them would be an awesome addition:
by @ahejlsberg:
The original issue #1003 got closed with the following comment:
A quick search suggests that there isn't a ticket for this yet. So here we go.
The text was updated successfully, but these errors were encountered: