Guards
Guards: type guards and assertions that narrow values (the enum guards are in enum).
| Export | What it does |
|---|---|
assert | Throws when a condition is falsy, and narrows its type otherwise. |
assertNever | Marks a code path as unreachable: in the default of a switch over a union, TypeScript fails when a member is not handled, and an unexpected value throws at run time. |
isArray | Checks whether a value is an array, whatever its items. |
isArrayOf | Checks whether a value is an array whose every item passes a type guard. |
isBoolean | Checks whether a value is a boolean. |
isDefined | Checks whether a value is neither null nor undefined: the opposite of isNullish. |
isFiniteNumber | Checks whether a value is a finite number: neither NaN nor an infinity. |
isFunction | Checks whether a value is callable: a function or a class. |
isNonEmptyArray | Checks whether an array has an item, and narrows it so that its first item is defined. |
isNotUndefined | Checks whether a value is not undefined; null passes, unlike with isDefined. |
isNull | Checks whether a value is null; undefined does not pass. |
isNullish | Checks whether a value is null or undefined: the opposite of isDefined. |
isNumber | Checks whether a value is a number other than NaN. |
isObject | Checks whether a value is a non-null object: plain object, array, class instance, date… isRecord accepts plain objects only. |
isRecord | Checks whether a value is a plain object: an object literal or Object.create(null). |
isString | Checks whether a value is a string primitive. |
isUndefined | Checks whether a value is undefined; null does not pass. |