asserts
The asserts() function throws when a predicate fails and narrows the input type when it passes.
Interactive example
Syntax
typescript
function asserts<
GenericInput extends unknown,
GenericPredicate extends GenericInput
>(
input: GenericInput,
predicate: (input: GenericInput) => input is GenericPredicate
): asserts input is GenericPredicateParameters
input: The value to validate.predicate: A type-guard predicate used to validate and narrow the input.
Return value
Nothing. It throws an AssertsError when the predicate fails.
See also
isType- Builds type guards based on runtime checksinstanceOf- Type guard using constructors
