See Union and intersections in the docs.

See the sections in this guide on Type aliases and Intersections.

Declare a set of allowed types.

string | boolean

For example, allow a variable to be of allowed types so you assign to either or even change.

let foo: string | boolean;
foo = 'a';
foo = 10;

TypeScript infers types on initialization, not assignment.

So this is valid but wonโ€™t give you any validation or intellisense as the type of foo is any.

let foo;
foo = 10;
foo = 'a';