Skip to content

optionalTypeGuard<T>

Widens a guard to also accept undefined, which is what an optional property or parameter reads as when it is left out.

Import:

import { optionalTypeGuard } from '@mnaoumov/typescript-lib/type-guards';

Signature:

function optionalTypeGuard(isValue: TypeGuard<T>): TypeGuard<T | undefined>

Parameters:

Parameter Type Description
isValue TypeGuard<T> The guard to widen.

Returns: TypeGuard<T | undefined> — A guard accepting what isValue accepts, or undefined.


Links to this page: