Advanced TypeScript
Utility Types
TypeScript utility types are standard reusable transformations such as Partial, Required, Pick, Omit, Record, ReturnType, Parameters, Extract, Exclude, NonNullable, and Awaited.
- Utility types encode common transformations
- Pick/Omit are shape tools, not DTO design strategy
- Partial is easy to overuse
- Record is useful for dictionaries with known key sets
- ReturnType and Parameters couple to implementation
| Utility | Meaning | Example use |
|---|---|---|
| Partial<T> | All properties optional | Draft/update object |
| Required<T> | All properties required | Normalized config |
| Pick<T, K> | Keep selected properties | Preview DTO |
| Omit<T, K> | Remove selected properties | Public shape without secret |
| Record<K, T> | Map keys to values | Handler table |
| ReturnType<F> | Function return type | Wrapper/helper |
| Extract<T, U> | Keep union members assignable to U | Filter variants |
| Exclude<T, U> | Remove union members assignable to U | Filter variants |
type Status = "idle" | "loading" | "success" | "error"
type Handler = () => void
const handlers: Record<Status, Handler> = {
idle: () => {},
loading: () => {},
success: () => {},
error: () => {},
}