Typeof Keyword, and Type Level
Gabriel Vergnaud discusses the "type level" and "value level" of TypeScript and JavaScript, and how type inference crosses the boundary between the two.
Gabriel aims to help others make this mental shift and use their existing knowledge of JavaScript at the type level to solve typing issues and bui
Transcript
0:00 I spoke to Gabriel Vergnaud about the experience of him building his course, which is Type-Level TypeScript, and what he learned along the way.
0:07 I realized that the type system of TypeScript was actually a programming language. You could apply the same concepts that you apply every day in JavaScript, like loops, decline variables, parameters, functions, and all of these things that we do all the time to the type level.
0:28 To a large extent, you could really reuse this knowledge at the type level. I call type level basically anything that's in any code that's in a type, after the type keyword, essentially, and the value level, so it's everything that you can do in JavaScript.
0:46 Show how those things map together so that other people could realize that and make this shift of perspective that will help them solve their typing issues and build a more robust mental model for the type system.
1:02 That's really interesting that you talk about the type level and the value level. That's the terms you use. Let's say we take the type of keyword in TypeScript. Is it right to say that it can take something from the value level and turn it into or bring it to the type level?
1:17 How would you explain that?
1:19 That's exactly true. Those two worlds, the world of types and the world of values, for the most part, they are separate. You can't really cross this boundary, but there is one way and one direction in which you can cross the boundary.
1:33 It's going from the value level to the type level, and that's called type inference. That's what TypeScript does all the time. You declare an object type and it has like two fields, a name and an age property, for instance, which are respectively a string and a number.
1:48 TypeScript is going to be able to infer the type of your object for you. It's going to lift this object that you created from the value level to the type level. That's what the type of keywords does.