TypeScript 7 · Utility types and narrowing
Remove null and undefined
Exclude null and undefined from a type.
type Defined = NonNullable<string | null | undefined>; // string
Official TypeScript 7 documentation
More utility types and narrowing commands
- Make all properties optional
- Pick or omit properties
- Type a dictionary
- Require or freeze properties
- Write a type guard
- Narrow an unknown value
All utility types and narrowing commands · TypeScript 7 cheatsheet