Indeed you are right
type Three = typeof three;
if typeof is in type position this is TS thing. I never paid attention to this
typeof
type
cool, 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
type Test = 1 const x = typeof Test; // the same as console.log(Test); // 'Test' only refers to a type, but is being used as a value here.(2693)
So it seems like type checker itself doesn't differentiate TS and JS versions of typeof and always returns error for JS version.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.