DEV Community

Discussion on: The Type of a `type` in Typescript

 
maxheiber profile image
Max Heiber

cool, huh!

It sneaks under the radar, since, as far as I can tell, there is no documentation on it.

Thread Thread
 
stereobooster profile image
stereobooster • Edited

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.