import { expected, success } from '../result'; import { create, Codec } from '../runtype'; export interface Constructor { new (...args: any[]): V; } export interface InstanceOf extends Codec { readonly tag: 'instanceof'; readonly ctor: Constructor; } export function InstanceOf(ctor: Constructor): InstanceOf { return create>( 'instanceof', value => (value instanceof ctor ? success(value) : expected(`${(ctor as any).name}`, value)), { ctor: ctor, show() { return `InstanceOf<${(ctor as any).name}>`; }, }, ); }