TypeScript 7 reference · 14 entries

TypeScript Type Operators and Keywords

keyof, typeof, indexed access, conditional and mapped types, template literal types, satisfies, as const, unknown, never, type predicates and enums, with runnable examples.

These are the building blocks the utility types are made from. Most are type-level only; satisfies and as const affect how a value's type is inferred, and enum is one of the few TypeScript features that generates runtime code.

NameDescriptionSince
keyof Produce a union of an object type's property names: keyof { a: 1; b: 2 } is 'a' | 'b'. 2.1
typeof (type query) In a type position, typeof takes the type of a value or function, so you don't have to write it twice.
Type[Key] Look up the type of a property with Type['key'], or of array elements with Type[number]. 2.1
conditional types (T extends U ? X : Y) Choose between two types based on a condition, like a ternary for types. The basis of many utility types. 2.8
infer Inside a conditional type, infer captures part of a type into a new type variable, e.g. the element type of an array. 2.8
mapped types ({ [K in Keys]: … }) Create a new object type by transforming every property of another, the way Partial and Readonly are built. 2.1
template literal types Build string literal types with template syntax: `on${string}` or combinations of unions like `${Size}-${Color}`. 4.1
satisfies Check that a value matches a type without widening it, so you keep the exact inferred type and still get errors. 4.9
as const Make a value deeply read-only with literal types: strings stay 'admin' instead of string, arrays become readonly tuples. 3.4
unknown The type-safe 'anything': a value of type unknown must be narrowed (checked) before you can use it, unlike any. 3.0
never The type with no values: for functions that never return, impossible branches, and exhaustiveness checks. 2.0
type predicates (x is T) A function returning 'value is Type' tells TypeScript that the value has that type wherever the function returns true. 1.6
assertion functions (asserts x is T) A function declared 'asserts value is Type' throws if the check fails, and narrows the type after the call. 3.7
enum Define a set of named constants. Prefer union types or 'as const' objects in new code; use enums when you need a runtime object. 1.0

Was this page helpful?