Union Type

Noun · Development

Definitions

  1. A type that represents a value which can be one of several specified types. Written as A | B in TypeScript, the compiler ensures you handle all possible variants before accessing type-specific properties.

    In plain English: A type that says 'this value could be one of several types' — and the compiler makes sure you check which one it is before using it.

    Example: "The API returns string | number, so you need a type guard before calling .toFixed()."

Related Terms