API Reference / @evolu/common / Type / instanceOf

Function: instanceOf()

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

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

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

ParameterType
ctorT

Returns

InstanceOfType<T>

Was this page helpful?