API reference › @evolu/common › Type › instanceOf
function instanceOf<Constructor>(
constructor: ValidateInstanceConstructor<Constructor>,
): InstanceOfType<Constructor>;
Defined in: packages/common/src/Type.ts:3270
Instance Type for one constructor.
Membership uses the intrinsic prototype chain, so subclasses are accepted,
equivalent constructors from other realms are rejected, and custom
Symbol.hasInstance implementations are ignored.
Use object instead when only the structure matters.
Example
import { assertFalse, assertTrue, instanceOf } from "@evolu/common";
class User {
readonly name: string;
constructor(name: string) {
this.name = name;
}
}
const UserInstance = instanceOf(User);
assertTrue(UserInstance.is(new User("Ada")));
assertFalse(UserInstance.is({ name: "Ada" }));