API reference@evolu/commonType › instanceOf

function instanceOf<T>(ctor: T): InstanceOfType<T>;

Defined in: packages/common/src/Type.ts:860

instanceof Type.

Ensures that a value is an instance of the given class constructor.

Example

class User {
  constructor(public name: string) {}
}

const UserInstance = instanceOf(User);

const result = UserInstance.from(new User("Alice")); // ok
const error = UserInstance.from({}); // err