is-kit

nullish

Nullability helpers to widen or narrow values such as undefined and null. For key-level optional fields inside struct, use optionalKey(...).

import { isString, nullable, nonNull, nullish, optional, required } from 'is-kit';
const maybeString = nullable(isString);
maybeString(null); // true
const notNull = nonNull(isString);
notNull('x'); // true
const maybe = nullish(isString);
maybe(undefined); // true
const maybeUndef = optional(isString);
maybeUndef(undefined); // true
const needValue = required(optional(isString));
needValue('ok'); // true
// optional(...) is value-level.
// For struct key-level optional properties, use optionalKey(...).