Remove `null` and `undefined` from a type.

Section: Common Utility Type Recipes

Use `NonNullable<T>`

typescript
typescript
type MaybeUser = { id: string } | null | undefined;
type User = NonNullable<MaybeUser>;
Explanation

Useful after validation or guard logic has removed nullable cases.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Common Utility Type Recipes
Use `Extract<T, U>`
Keep only members assignable to another type.
OpenIn sheettypescriptsame section
Use `Exclude<T, U>`
Remove members assignable to another type.
OpenIn sheettypescriptsame section
Use `Parameters<T>`
Extract a function’s parameter tuple.
OpenIn sheettypescriptsame section
Use `InstanceType<T>`
Get the instance type from a class constructor.
OpenIn sheettypescriptsame section
Paginated API response type
Model paginated collections with generics.
OpenIn sheettypescript1 tag match
Form field error map
Type validation errors by field name.
OpenIn sheettypescript1 tag match