-
Notifications
You must be signed in to change notification settings - Fork 1.1k
typeof operator isn't documented #1305
Comments
I came here because I couldn't find documentation for the |
@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. |
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. |
Like @estaub mentioned of |
@jpelton-stroud Sorry, but I'm not sure what your point was. If you were saying that the MDN doc covers use of const JoeSchmoe = { name: 'Schmoe, Joe', district: '42' }
type legislator = typeof JoeSchmoe // == { name: string; district: string } |
ah, apparently I fell prey to that "novice puzzlement" you mentioned :P Thank you for the clarification! |
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'd provide a PR, but the wording should be much more precise and consistent than I'm able to do. A starting point might be https://mariusschulz.com/blog/type-queries-and-typeof-in-typescript#typescripts-type-queries
The text was updated successfully, but these errors were encountered: