instance - nberlette/is GitHub Wiki
function isInstance<T>(it: unknown, constructor: Constructor<T>): it is T;
Checks if a given value is an instance of a specific class or constructor.
This is a type guard function that can be used to determine if a value is an instance of a class or constructor function, even if the class is not directly accessible in the current scope.
Name | Info |
---|---|
it |
The value to check. |
constructor |
The class or constructor function to check against. |
true
if it is an instance of the class; otherwise, false
.
Guards
function isInstance<T extends Constructor<any>>(
it: unknown,
constructor: T,
): it is InstanceType<T>;
Checks if a given value is an instance of a particular class or constructor.
Name | Info |
---|---|
it |
The value to check. |
constructor |
The class or constructor function to check against. |
true
if it is an instance of the class; otherwise, false
.
Guards
function isInstance<T extends Constructor<P>, P = InstanceType<T>>(
it: unknown,
constructor: T | Constructor<P> | P,
): it is InstanceType<T>;
Checks if a given value is an instance of a specific class or constructor.
Name | Info |
---|---|
it |
The value to check. |
constructor |
The class or constructor function to check against. |
true
if it is an instance of the class; otherwise, false
.
Guards