Skip to content

assertcheck v1.0.0


assertcheck / assert / instanceOf

Function: instanceOf()

ts
function instanceOf<T>(
   v, 
   ctor, 
   opts?): asserts v is T;

Defined in: src/assert.ts:404

Asserts that v is an instance of the given constructor. Narrows the type to T after the call.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
vunknownThe value to check.
ctor(...args) => TThe constructor to test against.
opts?OptsOptional message / context.

Returns

asserts v is T

Example

ts
assert.instanceOf(err, ValidationError, "must be a ValidationError")
err.field // TypeScript knows err is ValidationError

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.