Loading docs…
Loading docs…
Nullability helpers to widen or narrow values such as undefined and null. For key-level optional fields inside struct, use optionalKey(...)instead. Use isNil to check whether a value is nullish, and isNotNil for the inverse check or to remove nullish array entries while preserving their narrowed element type.
import {isNil,isNotNil,isString,nullable,nonNull,nullish,optional,required,} from 'is-kit';isNil(null); // trueisNil(undefined); // trueisNil(0); // false// isNil checks a value directly for null | undefined.const values: Array<string | null | undefined> = ['value', null, undefined];const presentValues = values.filter(isNotNil); // string[]// isNotNil excludes null | undefined and preserves generic narrowing.const maybeString = nullable(isString);maybeString(null); // trueconst notNull = nonNull(isString);notNull('x'); // trueconst maybe = nullish(isString);maybe(undefined); // true// nullish(isString) widens isString to also accept null or undefined.const maybeUndef = optional(isString);maybeUndef(undefined); // trueconst 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(...).