Type
Type aliases give a name to any type object shapes, unions, intersections, primitives, and more complex computed types.
Basic alias
Union types
A value can be one of several types. Use a type guard (see Basics) to narrow it before relying on type-specific behavior:
Intersection types
Combines multiple types into one that must satisfy all of them:
Literal types
Restrict a value to one or more exact values, rather than a general type:
Tuple types
Fixed-length arrays where each position has its own type:
Generic type aliases
Mapped types
Build a new type by transforming each property of an existing type:
Conditional types
Choose a type based on a condition, evaluated at the type level:
Built-in utility types
TypeScript ships several generic utility types built from mapped/conditional types, so you rarely need to write your own:
Partial<T>makes all properties optionalRequired<T>makes all properties requiredReadonly<T>makes all properties readonlyPick<T, K>keeps only the given keysOmit<T, K>removes the given keysRecord<K, V>builds an object type with keysKand valuesV
type vs interface
See Interface for the comparison.