assertInstanceOf

import { assertInstanceOf } from "jsr:@ende/assert";

function

function assertInstanceOf<T extends new (...args: any[]) => any>(actual: unknown, expectedType: T, msg: string = ): asserts actual is InstanceType<T>

Make an assertion that obj is an instance of type. If not then throw.

actual: unknown

The object to check.

expectedType: T

The expected class constructor.

msg: string =

The optional message to display if the assertion fails.

Example: Usage

import { assertInstanceOf } from "@ende/assert";

assertInstanceOf(new Date(), Date); // Doesn't throw
assertInstanceOf(new Date(), Number); // Throws

Source