jty
    Preparing search index...

    Function isA

    • Checks if a provided value is an instance of the provided class

      This does not throw for some cases where JavaScript chokes ()

      Type Parameters

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

      Parameters

      • x: unknown

        possibly an instance of a class

      • classConstructor: T

        a class constructor (usually starts with big letter!)

      Returns x is InstanceType<T>

      isA({}, Object) => true
      isA(Promise.resolve, Promise) => true
      isA(/hello/i, RegExp) => true
      isA('plain str', String) => false
      isA(new String('str obj'), String) => true
      isA(22, Number) => false
      isA(new Number(33), Number) => true
      isA(2, NaN) => false // Note that `2 instanceof NaN` throws

      if classConstructor is not a function.