Function: isInstanceOf()
ts
function isInstanceOf<T>(
value: unknown,
type: string,
ctor?: (...args: any[]) => T,
): value is T;Returns true if value is an instance of the class identified by type (and optionally ctor).
Type Parameters
| Type Parameter | Description |
|---|---|
T | The expected instance type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to test. |
type | string | The constructor name to compare against when instanceof is unavailable. |
ctor? | (...args: any[]) => T | Optional constructor to use for instanceof and Symbol.hasInstance checks. |
Returns
value is T
true when value is an instance of the class described by type/ctor.
Remarks
Performs three checks in order: instanceof ctor, Symbol.hasInstance, then constructor-name comparison. The constructor-name fallback handles cross-realm cases where instanceof fails.