mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 20:35:54 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
689 B
689 B
isNotNil
Checks if the given value is not null nor undefined.
This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to ensure it is not nullable.
Signature
function isNotNil<T>(x: T | null | undefined): x is T;
Parameters
x
(T | null | undefined
): The value to test if it is not null nor undefined.
Returns
(x is T
): True if the value is not null nor undefined, false otherwise.
Examples
// Here the type of `arr` is (number | undefined)[]
const arr = [1, undefined, 3];
// Here the type of `result` is number[]
const result = arr.filter(isNotNil);
// result will be [1, 3]