@salesforce/ts-types
    Preparing search index...

    Function getInstance

    • Given a deep-search query path, returns an object property or array value of an object or array as an instance of class type C, or undefined if a value was not found or was not type-compatible.

      class Example { ... }
      const obj = { foo: { bar: [new Example()] } };
      const value = getInstance(obj, 'foo.bar[0]', Example);
      // type of value -> Example

      Type Parameters

      Parameters

      • from: unknown

        Any value to query.

      • path: string

        The query path.

      • ctor: C

      Returns Nullable<InstanceType<C>>

    • Given a deep-search query path, returns an object property or array value of an object or array as an instance of class type C, or undefined if a value was not found or was not type-compatible.

      class Example { ... }
      const obj = { foo: { bar: [new Example()] } };
      const value = getInstance(obj, 'foo.bar[0]', Example);
      // type of value -> Example; value -> new Example()

      Type Parameters

      Parameters

      • from: unknown

        Any value to query.

      • path: string

        The query path.

      • ctor: C
      • defaultValue: InstanceType<C>

        The default to return if the query result was not defined.

      Returns InstanceType<C>