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 }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
The typeof operator, as used in type queries rather than Javascript, isn't documented, other than as used in documentation of other things, like type guards. Because it is overloaded from the Javascript operator, there can be lots of novice puzzlement.
If your reaction is "that can't possibly be", please look for yourself!
I came here because I couldn't find documentation for the switch statement in the handbook. It seems like there is a missing page for "expressions" that could cover typeof, switch and others.
I was trying to find out if it's possible to switch on the type of a variable. It's not obvious to me that the handbook shouldn't cover all the parts of the language. It certainly covers a lot of vanilla JavaScript already.
At least it would be nice if it said somewhere that this particular language construct is unmodified.
Joshua Pelton-Stroud (@jpelton-stroud) Sorry, but I'm not sure what your point was. If you were saying that the MDN doc covers use of typeof in TS as a type query operator, you'd be wrong; static typing is a foreign concept to JS that can't even begin to be discussed in JS terms. I suppose I should provide an example, to be crystal clear:
Activity
dwarburt commentedon Mar 10, 2020
I came here because I couldn't find documentation for the
switchstatement in the handbook. It seems like there is a missing page for "expressions" that could covertypeof,switchand others.estaub commentedon Mar 10, 2020
David Warburton (@dwarburt) AFAIK switch in Typescript is unmodified from Javascript. Is there something Typescript-specific you were looking for? The handbook doesn't cover most of vanilla Javascript, for obvious reasons. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch.
dwarburt commentedon Mar 10, 2020
I was trying to find out if it's possible to switch on the type of a variable. It's not obvious to me that the handbook shouldn't cover all the parts of the language. It certainly covers a lot of vanilla JavaScript already.
At least it would be nice if it said somewhere that this particular language construct is unmodified.
jpelton-stroud commentedon May 3, 2020
Like Ed Staub (@estaub) mentioned of
switch,typeofis also a native JS operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeofestaub commentedon May 3, 2020
Joshua Pelton-Stroud (@jpelton-stroud) Sorry, but I'm not sure what your point was. If you were saying that the MDN doc covers use of
typeofin TS as a type query operator, you'd be wrong; static typing is a foreign concept to JS that can't even begin to be discussed in JS terms. I suppose I should provide an example, to be crystal clear:jpelton-stroud commentedon May 3, 2020
ah, apparently I fell prey to that "novice puzzlement" you mentioned :P Thank you for the clarification!