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
In regards to type guards, one thing that is fairly common in the javascript world is checking a property to see if its a certain type.
varvariable: number|boolean[]|string;if(variable.length){// variable is of type boolean[] | string }else{// variable is of type number}
Would this be a possible thing to include in typescript?
One thing i see as an issue/blocker (probably why this hasn't already been implemented) is that length isn't a valid property of variable.
But i thought, just like how we can opt out of a strongly typed var with the any keyword, maybe we could "flatten" out a union type to show all it's properties.
I suggest doing something like so: (<all>variable).length or maybe variable?.length (or something else?)
In fact, i already implemented the latter, and it works great, but of course, ?. might be used for something else in the future (hint: C# 6). Maybe we can discuss this.
Where do the TS team stand on this?
The text was updated successfully, but these errors were encountered:
Hi guys,
In regards to type guards, one thing that is fairly common in the javascript world is checking a property to see if its a certain type.
Would this be a possible thing to include in typescript?
One thing i see as an issue/blocker (probably why this hasn't already been implemented) is that
length
isn't a valid property ofvariable
.But i thought, just like how we can opt out of a strongly typed var with the
any
keyword, maybe we could "flatten" out a union type to show all it's properties.I suggest doing something like so:
(<all>variable).length
or maybevariable?.length
(or something else?)In fact, i already implemented the latter, and it works great, but of course,
?.
might be used for something else in the future (hint: C# 6). Maybe we can discuss this.Where do the TS team stand on this?
The text was updated successfully, but these errors were encountered: