TypeScript - Utility Types

Core utilities

type User = { id: string; name: string; email?: string };

type UserPartial = Partial;
type UserRequired = Required;
type UserReadonly = Readonly;

type UserRecord = Record;

type UserIdName = Pick;
type UserNoEmail = Omit;

Union helpers

type A = 'a' | 'b' | 'c';

type NoB = Exclude; // 'a' | 'c'
type OnlyB = Extract; // 'b'

Function and class helpers

function f(a: number, b: string) { return { a, b } }

type FParams = Parameters;        // [number, string]
type FReturn = ReturnType;        // { a: number; b: string }

type DateCtorParams = ConstructorParameters; // [string | number | Date]
type DateInstance = InstanceType;            // Date

Awaited

type P = Promise;
type N = Awaited

; // number