Discriminated Union

Noun · Development

Definitions

  1. A union type where each member has a common literal property (the discriminant) that allows the type checker to narrow which variant is in use. Also called a tagged union or algebraic data type.

    In plain English: A value that can be one of several shapes, but always carries a label telling you which shape it currently is.

    Example: "We model API responses as a discriminated union — { status: "ok", data } | { status: "error", message } — so TypeScript narrows automatically."

Related Terms