Union Types, Type Guards, and Aliases

Learn to combine types and understand type guards and aliases.

Introduction to unions

TypeScript allows us to express a type as a combination of two or more other types. These types are known as union types, and they use the pipe symbol (|) to list all of the types that will make up this new type.

Consider the following code:

Get hands-on with 1200+ tech skills courses.