You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
enable type guards over string literal types #6028
Type guards could relate the common kind property to the corresponding object type in the union and narrow the type appropriately in the guarded block.
The original issue #1003 got closed with the following comment:
the remaining part is extending the type guards to support the string literal types. but this should be tracked by a different issue.
A quick search suggests that there isn't a ticket for this yet. So here we go.
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.
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.
Not sure if its listed anywhere, but i think this should show an error: (Hopefully in the IDE)
// declaretypeoptions='option1'|'option2';interfaceA{
possibleOptions: options;}/// use (given class B that implements interface A)varx=newB();if(x.possibleOptions==='option3'){// there is no way of getting here is all possible values are either 'option1' or 'option2', should error}
Activity
DanielRosenwasser commentedon Dec 10, 2015
Thanks for filing Aleksey-Bykov!
Eyas commentedon Jan 22, 2016
Is this no longer intended for TypeScript 1.8?
DanielRosenwasser commentedon Jan 22, 2016
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.
Eyas commentedon Jan 22, 2016
Daniel Rosenwasser (@DanielRosenwasser) is there an issue/set of issues to track about the type system work?
zpdDG4gta8XKpMCd commentedon Jan 22, 2016
what are the more exciting features?
DanielRosenwasser commentedon Jan 22, 2016
Eyas (@Eyas) Yes. 😉
DanielRosenwasser commentedon Jan 22, 2016
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.
zpdDG4gta8XKpMCd commentedon Jan 22, 2016
good, that is what this issue is about, I thought there might be more to that
shaharmor commentedon Mar 29, 2016
Not sure if its listed anywhere, but i think this should show an error: (Hopefully in the IDE)
DanielRosenwasser commentedon Jun 23, 2016
Can we say that this has been fixed by #9163?
zpdDG4gta8XKpMCd commentedon Jun 23, 2016
yes, thanks
On Jun 23, 2016 02:16, "Daniel Rosenwasser" notifications@github.com
wrote: