You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Item 8: Know How to Tell Whether a Symbol Is in the Type Space or Value Space
Things to Remember
Know how to tell whether you're in type space or value space while reading a TypeScript expression. Use the TypeScript playground to build an intuition for this.
Every value has a static type, but this is only accessible in type space. Type space constructs such as type and interface are erased and are not accessible in value space.
Some constructs, such as class or enum, introduce both a type and a value.
typeof, this, and many other operators and keywords have different meanings in type space and value space.
typeT1=typeofjane;// ^? type T1 = PersontypeT2=typeofemail;// ^? type T2 = (to: Person, subject: string, body: string) => Responseconstv1=typeofjane;// Value is "object"constv2=typeofemail;// Value is "function"
typePersonEl=Person['first'|'last'];// ^? type PersonEl = stringtypeTuple=[string,number,Date];typeTupleEl=Tuple[number];// ^? type TupleEl = string | number | Date
functionemail({to: Person,// ~~~~~~ Binding element 'Person' implicitly has an 'any' typesubject: string,// ~~~~~~ Binding element 'string' implicitly has an 'any' typebody: string// ~~~~~~ Binding element 'string' implicitly has an 'any' type}){/* ... */}