Narrowing Types
Unions will cause errors if all types don't have a property
Error
Correct
Guards
Typeof
TypeScript expects this to return a certain set of strings:
"string"
"number"
"bigint"
"boolean"
"symbol"
"undefined"
"object"
"function"
Boolean
Coerced to false
0
NaN
""
(the empty string)0n
(thebigint
version of zero)null
undefined
instanceof
x instanceof Foo checks whether the prototype chain of x
contains Foo.prototype
Advanced Types => Type predicates
Way 1
Way 2
Last updated