Creates an OptionalTypeGuard that checks that the value is either undefined or of type T.
OptionalTypeGuard
undefined
T
Can be shortened with TypeGuard.optional.
TypeGuard.optional
The type to make optional
The type guard for the base type T
A type guard for T | undefined
T | undefined
const isOptionalNumber = isOptional(isNumber); // or isNumber.optional()isOptionalNumber(5); // trueisOptionalNumber(undefined); // trueisOptionalNumber("hello"); // false Copy
const isOptionalNumber = isOptional(isNumber); // or isNumber.optional()isOptionalNumber(5); // trueisOptionalNumber(undefined); // trueisOptionalNumber("hello"); // false
Creates an
OptionalTypeGuardthat checks that the value is eitherundefinedor of typeT.Can be shortened with
TypeGuard.optional.