TSworkingts-evergreen

TypeScript Utility Types

Type-level tooling, included.

TypeScript ships a set of generics for common transformations β€” Pick, Omit, Partial, Required, Record, ReturnType β€” that replace handwritten conditional types in 90% of cases.

Partial and Required

Partial<T> makes every property optional; Required<T> makes every property required. Use them for update payloads (Partial) and validated inputs (Required).

Pick and Omit

Pick<T, K> keeps named keys; Omit<T, K> removes named keys. Use them when modelling DTOs that are subsets of a domain entity.

Record

Record<K, V> is the typed equivalent of { [key: K]: V }. The first generic constrains the key type β€” use string literal unions for closed key sets.

ReturnType, Parameters, Awaited

ReturnType<typeof f>, Parameters<typeof f>, and Awaited<T> extract types from existing function signatures. Useful for keeping types in sync with the runtime.

Extracting from functions

When you don't control a function's signature, derive types from it instead of duplicating them. Parameters<typeof f> pulls the argument tuple, ReturnType<typeof f> the return type, and Awaited<T> unwraps a Promise β€” so a single source function stays the canonical contract and refactors propagate automatically. Extract, Exclude, and NonNullable work the other direction, narrowing a union down to the members you care about.

Try it 5 examples

Partial and Required

TSintro
Press Run to execute

patch logs as {"name":"Ada"} because Partial<User> lets you supply just the fields you're changing, while full must carry every field β€” including the normally-optional age β€” since Required<User> strips the ?.