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

All utility types and narrowing commands · TypeScript 7 cheatsheet

Was this page helpful?