Skip to main content

isNonNull()

isNonNull<T>(value): value is T

Checks if a nullable value is not null.

Type guard that narrows Nullable<T> to T by excluding null.


Type Parameters​

T: T​

The type of the value.


Parameters​

value: T | null​

The nullable value to check.


Returns: value is T​

true if the value is not null, false otherwise.


Since​

1.0.0


Example​

function process(data: `Nullable<string>`) {
if (isNonNull(data)) {
// data is now typed as string
console.log(data.toUpperCase());
}
}

How it works?​

Type guard that checks if a value is not null.

Type Narrowing​

Common Checks​

ValueResult
undefined true
0 true
'' true
false true
null false

vs isNonNullable​


Use Cases​

Ensure value existence πŸ“Œβ€‹

Strictly check that a value is not null (allows undefined). Useful when null has a specific semantic meaning different from undefined.

if (isNonNull(value)) {
// value is T | undefined, but not null
}