TypeScript Utility Types
NonNullable<T> — exclude null and undefined
NonNullable models a non-nullish type under strictNullChecks. In the installed compiler its declaration uses an intersection with {}. It is not a truthiness filter: zero, false and the empty string remain valid when included in T. It does not throw, remove null values from a collection, or establish that a runtime input is present. Example output: "0". Verified with strict TypeScript 5.8.3, ES2022 and Node.js 22.16.0. This utility affects static typing; no runtime validation or transformation is supplied by the type itself.
Formal Syntax & Structure
typescript syntaxtypescript
NonNullable<T>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| T | type parameter | Type from which null and undefined are excluded. |
Working Example
Example Snippettypescript
type Quantity = NonNullable<number | null | undefined>;const value: Quantity = 0;console.log(value);