Skip to main content

isNotNil

A function that checks whether a given argument is neither null nor undefined, and if so, narrows the type to the original argument type.


Code

🔗 View source code

Interface

typescript
const isNotNil: <T>(val: T | null | undefined) => val is T

Usage

typescript
import { isNotNil } from '@modern-kit/utils';

isNotNil(1); // true
isNotNil(false); // true
isNotNil("str"); // true
isNotNil({}); // true

isNotNil(undefined); // false
isNotNil(null); // false