Skip to content

instanceOf() ​

ts
function instanceOf<T>(constructor): Parser<T>

Returns a parser that checks whether the data is an instance of the given constructor.

Example ​

ts
const parseError = instanceOf(Error)
parseError(new Error()) // -> Success<Error>

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
constructor(...args) => Tthe right-hand side argument of the instanceof operator

Returns ​

Parser<T>