Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

NonNullable

NonNullable<Type> removes null and undefined from a type. It is useful for describing values that remain after nullish cases have been ruled out.

Since
2.8

How it works

NonNullable<Type> transforms a type by removing null and undefined from it. Applied to a union, it preserves the remaining members, making it useful for representing values after validation or other checks.

Syntax

type NonNullable<Type> = Type & {};

Parameters

NameTypeDescription
TypetypeThe input type from which null and undefined are excluded.

Returns

A type derived from Type with null and undefined excluded.

Key points

  • NonNullable<Type> creates a version of Type without null or undefined.
  • For string | number | undefined, the resulting type is string | number.
  • For string[] | null | undefined, the resulting type is string[].

Common mistakes

  • NonNullable is built into TypeScript and does not need to be imported.
  • It only excludes null and undefined; other union members remain unchanged.

Example: Removing null and undefined from a value

type Present<T> = NonNullable<T>;

function requireValue<T>(value: T): NonNullable<T> {
  if (value == null) throw new Error("Missing value");
  return value as NonNullable<T>;
}

const name: string | undefined = "Ada";
const presentName = requireValue(name);
console.log(presentName.toUpperCase());

This runnable example removes nullish possibilities from a generic result after a runtime check.

When to use it

Validated values

Define a field or result that must contain a concrete value after validation.

API and configuration modeling

Derive a non-nullable type from an API or configuration union.

Generic helpers

Express generic return types after rejecting nullish inputs.

  • Exclude
  • Required
  • strictNullChecks
  • Utility Types

Source: Documentation - Utility Types - TypeScript. Checked 2026-10-15.