The instance schema validates that the input is an instance of a class.
instance
import { instance } from "typerun/schema";import { is } from "typerun";class MyClass {}const isInstance = is(instance(MyClass))(new MyClass());console.log(isInstance); // trueconst isNotInstance = is(instance(MyClass))({});console.log(isNotInstance); // false Copy
import { instance } from "typerun/schema";import { is } from "typerun";class MyClass {}const isInstance = is(instance(MyClass))(new MyClass());console.log(isInstance); // trueconst isNotInstance = is(instance(MyClass))({});console.log(isNotInstance); // false
TypeScript will raise a compilation error if you try to use the instance schema with a class with a private constructor.
The class to validate.
Rest
The
instance
schema validates that the input is an instance of a class.Example
Caveats
TypeScript will raise a compilation error if you try to use the
instance
schema with a class with a private constructor.