Skip to main content
Module

x/unknownutil/is.ts>isInstanceOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isInstanceOf
import { isInstanceOf } from "https://deno.land/x/unknownutil@v3.18.0/is.ts";

Return true if the type of x is instance of ctor.

To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.

import { is } from "@core/unknownutil";

const isMyType = is.InstanceOf(Date);
const a: unknown = new Date();
if (isMyType(a)) {
  // a is narrowed to Date
  const _: Date = a;
}

Type Parameters

T extends new (...args: any) => unknown

Returns

Predicate<InstanceType<T>> & WithMetadata<IsInstanceOfMetadata>