assertInstance()function

assertInstance(value: unknown, type: Class<T>): asserts value is T
ParamType
valueunknown
The value to assert. required
typeClass<T>
The class value must be an instance of. required
Return
asserts value is T
Throws
RequiredError
If value is not an instance of type.

Assert that a value is an instance of something.

Examples

assertInstance(new Date(), Date); // passes