object-transforms
Required<T>
Removes optionality from every property of T, producing a type where all fields must be present. The -? mapping modifier strips the ? flag from every key.
type Required<T> = { [P in keyof T]-?: T[P] } Usage patterns
| Pattern | Purpose |
|---|---|
| Required<T> | Force every property to be present after validation |
| Required<Pick<T, K>> | Require only a specific subset of keys |
| -? | The mapping modifier internally used to strip optionality |
| Required<Partial<T>> | Round-trips back to a fully-required T |
Examples
interface Options { host?: string; port?: number }
type ResolvedOptions = Required<Options>; Both host and port become required: { host: string; port: number }
function resolve(o: Options): Required<Options> {
return { host: o.host ?? 'localhost', port: o.port ?? 80 };
} Common pattern: accept optional config, return fully-populated version
type WithId<T> = Required<Pick<T, 'id'>> & Omit<T, 'id'>; Requires only the id field while leaving other keys unchanged
type A = { x?: number | undefined };
type B = Required<A>; B is { x: number | undefined } — Required strips ? but not the |undefined union
Gotcha
Required removes the ? modifier but does not remove `undefined` from a property's type union. Use NonNullable on the value type if you also need to exclude undefined.
Related utility types
Partial<T>
Constructs a type where every property of T is set to optional. Useful for representing update payloads, patch objects, and configuration overrides where all fields may be omitted.
Readonly<T>
Marks every property of T as readonly, preventing reassignment after construction. Only enforced at compile-time — the underlying object is still mutable at runtime.
NonNullable<T>
Removes null and undefined from the type T. In TS 4.9+ it is implemented as `T & {}`, which drops nullish members without altering the rest.
Pick<T, K>
Builds a new type containing only the properties from T whose keys are in the union K. Ideal for narrowing large interfaces to the subset a function or component actually needs.
Omit<T, K>
Constructs a type by removing the properties in K from T. Unlike Pick, its K is not constrained to keyof T, so extra keys are silently ignored.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never