Const
class MyClass {}
function MyConstructor() {}
ClassSchema.parse(MyClass); // ✓ Valid
ClassSchema.parse(MyConstructor); // ✓ Valid
ClassSchema.parse(Array); // ✓ Valid
ClassSchema.parse(Date); // ✓ Valid
ClassSchema.parse(() => {}); // ✗ Throws validation error
ClassSchema.parse({}); // ✗ Throws validation error
A Zod schema that validates JavaScript classes or constructor functions.
This schema validates values that can be used as constructors, including ES6 classes, traditional constructor functions, and built-in constructors. It uses the isConstructible guard function to determine if a value can be invoked with the
new
operator to create object instances.