instanceOf<T>(object: unknown, declaration: Constructor<T>, loose?: boolean): object is T
Performs a loose instance check by comparing class names up the prototype
chain if instanceof initially fails. To disable this loose check,
pass false as the 3rd argument.
Generics can be used to type the object being checked. This will default
to the declaration passed to the 2nd argument.
instanceOf<ParseError>(error, Error);
Loose checks can be useful if multiple copies of the same class declaration
exists in the module tree. For example, multiple versions of the same package are imported.
Performs a loose instance check by comparing class names up the prototype chain if
instanceof
initially fails. To disable this loose check, passfalse
as the 3rd argument.Generics can be used to type the object being checked. This will default to the declaration passed to the 2nd argument.