

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Narrowing Types
incomplete
2: Unknown Type
incomplete
3: Type Hierarchy
incomplete
4: Narrowing Using In
incomplete
5: Type Predicates
incomplete
6: Exhaustive Checks
incomplete
7: Guard Clauses
incomplete
8: Type Assertion
incomplete
9: Double Assertion
incomplete
10: Non-Null Assertion
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
All the types in TypeScript can be arranged into a hierarchy of sorts. I've drawn one below:
Obviously I didn't list every type, but the goal here is to show you how narrowing works in TypeScript, and why you should care. Some key points:
any and unknown are at the top of the hierarchy, the weird one is actually the any type, because it just breaks all the rules, allowing you to do whatever you want with it.never is at the bottom of the hierarchy, because it represents values that can't occur."armin" is assignable to "armin" | "eren" which is assignable to string which is assignable to any."armin" | "eren" is not assignable to "armin" because what would happen if the value happened to be "eren"?undefined and null are assignable to void (at least, when strictNullChecks is disabled), but not the other way around.Our AI magic™ uses sentiment analysis to algorithmically deduce whether user feedback is positive or negative.