Suggest an editImprove this articleRefine the answer for “What does NonNullable<T> do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`NonNullable<T>`** is a utility type that strips `null` and `undefined` from type `T`: if `T` is `null` or `undefined`, the result is `never`, otherwise `T` itself is returned. **Key point:** it is implemented as the conditional type `T extends null | undefined ? never : T` and is used for safely accessing values after a `null`/`undefined` check.Shown above the full answer for quick recall.Answer (EN)Image### Definition In the standard library it is implemented like this: ```javascript type NonNullable<T> = T extends null | undefined ? never : T; ``` That is: if `T` is `null` or `undefined`, the result is `never`; otherwise `T` itself is returned. --- ### Usage examples ```javascript type A = NonNullable<string | null | undefined>; // string type B = NonNullable<number | undefined>; // number type C = NonNullable<null | undefined>; // never type D = NonNullable<string | null>; // string ``` --- ### Practical use 1. **Safely accessing values after a check:** ```javascript function getLength(value: string | null) { if (value) { let safe: NonNullable<typeof value> = value; // now definitely a string return safe.length; } return 0; } ``` 2. **Typing API responses after filtering out null:** ```javascript const users = [ "Tom", null, "Bob" ]; const valid = users.filter(Boolean) as NonNullable<typeof users[number]>[]; // valid: string[] ``` 3. **Combined with other utility types:** ```javascript type User = { name?: string | null }; type SafeUser = NonNullable<User["name"]>; // string ``` --- ### In short | Utility | Purpose | |---|---| | `NonNullable<T>` | Removes `null` and `undefined` | | `Partial<T>` | Makes all fields optional | | `Required<T>` | Makes all fields required | | `Readonly<T>` | Makes all fields read-only | | `Extract<T, U>` | Keeps the intersection of types | | `Exclude<T, U>` | Removes the intersection of types |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.