BUPKIS
    Preparing search index...

    Function isA

    • Generic type guard for instanceof checks.

      This function provides a type-safe way to check if a value is an instance of a given constructor, with proper type narrowing for TypeScript. It combines the null/object check with instanceof to ensure the value is a valid object before performing the instance check.

      Type Parameters

      • T extends Constructor

        The constructor type to check against

      Parameters

      • value: unknown

        Value to test

      • ctor: T

        Constructor function to check instanceof

      Returns value is InstanceType<T>

      true if the value is an instance of the constructor, false otherwise

      const obj = new Date();
      if (isA(obj, Date)) {
      // obj is now typed as Date
      console.log(obj.getTime());
      }