Skip to content

NonNullable

Since 1.0.0

Exclude null and undefined from a type.

Signature

typescript
type NonNullable<T> = T & {}

Parameters

ParameterDescription
TThe type to make non-nullable

Description

Removes null and undefined from a type. This is similar to TypeScript's built-in NonNullable but implemented differently for broader compatibility.

Examples

Basic Usage

typescript
import type { NonNullable } from 'uni-types'

type Clean = NonNullable<string | null | undefined> // string
type Clean2 = NonNullable<number | null> // number

With Object Types

typescript
interface User {
  name: string | null
  email: string | undefined
}

type CleanUser = NonNullable<User>
// User (null/undefined remain in properties, use NoNullish for deep removal)

Released under the MIT License.