I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
The answer is that we can never ask about the types of types in TypeScript.
You can ask if type has a type(kind) at the type level also. You can do that by conditional type:
typeIsKindOfString<T>=Textendsstring?true:falsetypeResultTrue=IsKindOfString<"Hi I am type, don't confuse me with value">// truetypeResultFalse=IsKindOfString<1>// false
In #TypeScript the confusion I see often is using `keyof` in the same way we use `instanceof`,`typeof` class T {} // Type & Value type TypeLevel = keyof T // Type type TypeLevel2 = typeof T // Type const ValueLevel = typeof T // Value const ValueLevel2 = T instanceof T //Value
Thanks for your comment!
Your example using conditional types shows that we can ask TypeScript questions about types.
But one question we cannot ask is what the type of a type is.
This is a translation of your example from types to sets (in the sense of "set theory"). The TLDR is:
typeof is like "memberOf" in set theory
extends is like subsetOf in set theory
TS's type theory is like a set theory where sets cannot be members of other sets. But they are allowed to be subsets of other sets.
"foo" // a value
Set{"foo"} // the singleton set containing the value "foo"
"foo" memberOf Set{"foo"} // true statement
Set{ the infinitude of strings } // set containing "foo", "blah blah blah", the Gettysburg address, etc.
Set{"foo"} subsetOf Set{ the infinitude of strings } // true statement
Set{"foo"} memberOf SetX // this is the kind of thing TS won't let us ask
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.
You can ask if type has a type(kind) at the type level also. You can do that by conditional type:
Playground
Also my latest tweet about confusion in Type level and Value level operators:
Thanks for your comment!
Your example using conditional types shows that we can ask TypeScript questions about types.
But one question we cannot ask is what the type of a type is.
This is a translation of your example from types to sets (in the sense of "set theory"). The TLDR is:
typeof
is like "memberOf" in set theoryextends
is likesubsetOf
in set theoryTS's type theory is like a set theory where sets cannot be members of other sets. But they are allowed to be subsets of other sets.