I rushed and used the wrong terminology in my last reply, sorry about that.
Here is type-level typeof, I promise it is a thing and is distinct from value-level/JS typeof. Type-level typeof returns a type. JS typeof returns a string.
constthree=3;// all uses of `typeof` below are in type position.// this is not the same as JS `typeof`typeThree=typeofthree;constx:typeofthree=3;declarefunctionfoo(param:typeofthree):void;
I rushed and used the wrong terminology in my last reply, sorry about that.
Here is type-level
typeof
, I promise it is a thing and is distinct from value-level/JStypeof
. Type-leveltypeof
returns a type. JStypeof
returns a string.typescriptlang.org/play/?ssl=9&ssc...
Indeed you are right
if
typeof
is intype
position this is TS thing. I never paid attention to thiscool, huh!
It sneaks under the radar, since, as far as I can tell, there is no documentation on it.
But the error is the same as if you try to use type in place of value
So it seems like type checker itself doesn't differentiate TS and JS versions of
typeof
and always returns error for JS version.