Skip to content

Guards ​

Guards: type guards and assertions that narrow values (the enum guards are in enum).

ExportWhat it does
assertThrows when a condition is falsy, and narrows its type otherwise.
assertNeverMarks 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.
isArrayChecks whether a value is an array, whatever its items.
isArrayOfChecks whether a value is an array whose every item passes a type guard.
isBooleanChecks whether a value is a boolean.
isDefinedChecks whether a value is neither null nor undefined: the opposite of isNullish.
isFiniteNumberChecks whether a value is a finite number: neither NaN nor an infinity.
isFunctionChecks whether a value is callable: a function or a class.
isNonEmptyArrayChecks whether an array has an item, and narrows it so that its first item is defined.
isNotUndefinedChecks whether a value is not undefined; null passes, unlike with isDefined.
isNullChecks whether a value is null; undefined does not pass.
isNullishChecks whether a value is null or undefined: the opposite of isDefined.
isNumberChecks whether a value is a number other than NaN.
isObjectChecks whether a value is a non-null object: plain object, array, class instance, date… isRecord accepts plain objects only.
isRecordChecks whether a value is a plain object: an object literal or Object.create(null).
isStringChecks whether a value is a string primitive.
isUndefinedChecks whether a value is undefined; null does not pass.

Generated from the JSDoc of the sources.