TypeScript Types Cheat Sheet: Utility Types, Narrowing and Generics
Checked against TypeScript TypeScript 7.0.2 and 5.9.3 (examples compiled with both) on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers who write TypeScript every day but still look up how Omit differs from Exclude or why a union check doesn't narrow. It covers the type system only, not compiler options. Every example in the rows and the worked example was compiled with tsc --strict on TypeScript 7.0.2 (the Go-based compiler) and on 5.9.3, the version this site's repo uses, and both gave the same errors.
When to use what
Start with narrowing, not assertions. A switch on a literal kind or status field (a discriminated union) gives you exact types in each branch and, with a never check in the default case, a compile error when someone adds a new variant. as just tells the compiler to trust you.
Take unknown for anything that comes from outside: JSON, catch variables, message events. You can't call methods on it until you narrow it, which is the point. any switches checking off for everything it touches and spreads through return types. Keep any for migration shims, and grep for it later.
Use satisfies when you want the compiler to check an object against a type but keep the literal types it inferred. Use an annotation when you want the wider type on purpose, for example a config that will be mutated later.
For utility types, Pick and Omit work on object keys, while Extract and Exclude work on union members; mixing them up is the most common error we see in reviews. If you are typing an API response, generate a first draft with JSON to TypeScript, and if you also need runtime checks, JSON to Zod gives you a schema you can infer types from. Our generics guide and utility types post go deeper than a cheat sheet can.
Version numbers are when each type was added, from the utility types reference.
Partial<User>Make every property optional; good for PATCH bodies (2.1)
Required<T> / Readonly<T>Remove ? from every property, or mark every property readonly
Pick<User, "id" | "name">Keep only the listed keys of an object type
Omit<User, "id">Drop the listed keys; combine as Partial<Omit<User, "id">> for an update type
Record<Keys, V>Object type with known keys (or string) mapped to one value type
Exclude<"a" | "b" | "c", "a">Remove union members; this gives "b" | "c"
Extract<T, U>Keep only the union members assignable to U
NonNullable<T>Remove null and undefined from a type
ReturnType<typeof f> / Parameters<typeof f>Function return type, or its parameters as a labelled tuple such as [a: number, b: string]
Awaited<Promise<Promise<number>>>Unwrap promises recursively; this gives number (4.5)
NoInfer<T>Stop a parameter position from widening a type argument; pick(["a","b"], "c") became an error (5.4)
typeof x === "string"Narrow primitives; remember typeof null is "object", so check for null as well
"name" in xNarrow by property; since 4.9 it also works on object, adding Record<"name", unknown>
x instanceof DateNarrow by class via the prototype chain
switch (o.status) { … }Discriminated union: a shared literal field narrows to the matching variant in each case
const _x: never = o;Exhaustiveness check in default; an unhandled variant gives error TS2322 'not assignable to type never'
function isString(x: unknown): x is stringType predicate; callers get string in the true branch
value != nullLoose inequality removes both null and undefined in one check
{ port: 3000 } satisfies Record<string, string | number>Check the object but keep port typed as number; the annotated version gave string | number
let v: unknownAccepts any value but blocks member access until narrowed (error TS18046 'is of type unknown')
let v: anyDisables checking; anyVal.foo.bar() compiled with no error at all
function fail(): neverReturn type for functions that always throw or never finish
object vs Object vs {}object means any non-primitive; the handbook says to always use object, not Object
<T extends { length: number }>Constrain a type parameter; passing 42 failed with TS2345
<T, K extends keyof T>(obj: T, key: K): T[K]Tie a key argument to the object's keys; a typo is a compile error
<T extends HTMLElement = HTMLDivElement>Default type argument, used when it is omitted or can't be inferred
keyof UserUnion of an object type's keys
User["role"]Indexed access: the type of one property; you must index with a type, not a const
(typeof roles)[number]Element type of an as const array; gave "admin" | "user" | "guest" here
Conditional type rows follow the conditional types handbook page.
{ [K in keyof T]: boolean }Mapped type: build a new object type from every key of T
{ -readonly [K in keyof T]-?: T[K] }Strip readonly and ? from every property
{ [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K] }Rename keys with as and template literals (4.1+)
[K in keyof T as Exclude<K, "kind">]Drop a key by mapping it to never
T extends string ? A : BConditional type; picks a branch based on assignability
T extends Array<infer I> ? I : TUse infer to pull a type out of another type
[T] extends [any] ? T[] : neverWrap in brackets to stop distribution: gave (string | number)[] instead of string[] | number[]
Worked example: Make the compiler catch a new order status you forgot to handle
Start with a union where every variant has a literal status field, and add a never check in the default branch:
type Order =
| { status: "pending"; createdAt: Date }
| { status: "paid"; paidAt: Date; amount: number }
| { status: "refunded"; refundId: string };
function label(o: Order): string {
switch (o.status) {
case "pending": return "waiting since " + o.createdAt.toISOString();
case "paid": return `paid ${o.amount}`;
default: {
const unhandled: never = o;
return unhandled;
}
}
}
Run the compiler:
$ tsc --noEmit --strict types.ts
types.ts(11,13): error TS2322: Type '{ status: "refunded"; refundId: string; }' is not assignable to type 'never'.
We got this exact line from both TypeScript 7.0.2 and 5.9.3. Inside each case, o is narrowed to one variant, which is why o.amount is allowed only under "paid". By the time control reaches default, the only variant left is the refunded one, and it can't be assigned to never, so the error names it for you. Add a case "refunded" and the error goes away. Next month, when someone adds a "cancelled" status, this function fails the build instead of silently returning undefined.
Common mistakes
Using
Omiton a union of string literals, orExcludeon an object type.OmitandPicktake object keys;ExcludeandExtractfilter union members. Pick the pair that matches what you hold.Checking
typeof x === "object"and assumingxis not null.Add
x !== null(or a truthiness check), becausetypeof nullis also"object".Annotating a config object with
Record<string, string | number>and then losing the literal types.Use
satisfiesinstead of an annotation so the check happens but each property keeps its inferred type.Typing parsed JSON or a
catchvariable asany.Use
unknownand narrow withtypeof,inor a type predicate before using it.Writing
Person[key]wherekeyis aconstvariable.Index with a type:
Person[typeof key]or a type alias. The compiler's error message suggeststypeof keyitself.Being surprised that a conditional type returns
string[] | number[]for a union input.That is distribution over a naked type parameter. Wrap both sides in brackets,
[T] extends [any], when you want the union treated as one type.
Related cheat sheets
Sources
- https://www.typescriptlang.org/docs/handbook/utility-types.html
- https://www.typescriptlang.org/docs/handbook/2/narrowing.html
- https://www.typescriptlang.org/docs/handbook/2/generics.html
- https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html
- https://www.typescriptlang.org/docs/handbook/2/mapped-types.html
- https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
- https://www.typescriptlang.org/docs/handbook/2/functions.html
- https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html
- https://devblogs.microsoft.com/typescript/
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.