is-kit

nullish

Nullability helpers to widen or narrow values such as undefined and null. For key-level optional fields inside struct, use optionalKey(...)instead. Use isNil when you only need to check whether the value itself is null or undefined.

import { isNil, isString, nullable, nonNull, nullish, optional, required } from 'is-kit';
isNil(null); // true
isNil(undefined); // true
isNil(0); // false
// isNil checks a value directly for null | undefined.
const maybeString = nullable(isString);
maybeString(null); // true
const notNull = nonNull(isString);
notNull('x'); // true
const maybe = nullish(isString);
maybe(undefined); // true
// nullish(isString) widens isString to also accept null or undefined.
const maybeUndef = optional(isString);
maybeUndef(undefined); // true
const needValue = required(optional(isString));
needValue('ok'); // true
// isNil checks the value itself.
// nullish(...) widens another guard to accept null or undefined.
// optional(...) is value-level.
// For struct key-level optional properties, use optionalKey(...).