Function instance

  • The instance schema validates that the input is an instance of a class.

    Example

    import { instance } from "typerun/schema";
    import { is } from "typerun";

    class MyClass {}
    const isInstance = is(instance(MyClass))(new MyClass());
    console.log(isInstance); // true

    const isNotInstance = is(instance(MyClass))({});
    console.log(isNotInstance); // false

    Caveats

    TypeScript will raise a compilation error if you try to use the instance schema with a class with a private constructor.

    Type Parameters

    • Class

    Parameters

    • className: (new (...args) => Class)

      The class to validate.

        • new (...args): Class
        • Parameters

          • Rest ...args: any

          Returns Class

    Returns Schema<Class>