Types

Contents

Types#

TypeScript’s type system is structural: two types match if their structures match, regardless of name. Build programs out of primitives, object structures, unions, intersections, and a handful of generic operators (keyof, typeof, Pick, Omit, Partial, conditional types) that compute types from other types.

For the lexical surface that produces these types, see Syntax. For class-shaped types, see OOP.

Pages#

Primitives

string, number, bigint, boolean, null, undefined, symbol, void, never, any, unknown.

Primitives
Object types

Inline annotations, type aliases, interface.

Object types
Arrays and tuples

T[], readonly T[], fixed-length and labelled tuples.

Arrays and tuples
Unions and intersections

A | B, A & B, discriminated unions.

Unions and intersections
Literal types

One-value types; as const; template literal types.

Literal types
Generics

<T> slots, extends constraints, generic classes.

Generics
Type operators

keyof, typeof, Pick, Omit, Partial, ReturnType.

Type operators
Conditional and mapped

Conditional types, infer, mapped types.

Conditional and mapped
Casting

as assertions, satisfies, zod for runtime validation.

Casting

References#