API reference / @evolu/common / Type / instanceOf
Function: instanceOf()
function instanceOf<T>(ctor): InstanceOfType<T>;
Defined in: packages/common/src/Type.ts:743
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
Type Parameters
| Type Parameter |
|---|
T extends (...args) => any |
Parameters
| Parameter | Type |
|---|---|
ctor | T |