November 2018
Beginner
502 pages
10h 22m
English
Type guards allow us to narrow down the specific type of an object within a conditional branch of code. They are useful when working with union types, when we need to implement a branch of code that deals with a specific type in the union.
We already worked with a type guard in the last section when we implemented the intializeValue function. The switch statement on the discriminant property control allowed us to set the value on each type in the union.
There are other ways we can implement type guards. The following sections go through different ways.
Read now
Unlock full access