import { Err, Result } from "../result"; import { Type } from "../type"; export type Constructor = Function & { prototype: T } export class InstanceOf extends Type { readonly klass: Constructor; constructor(klass: Constructor) { super(); this.klass = klass; } check(val: any): Result { if(val instanceof this.klass) return val as Result; return new Err(`${val} is not an instance of ${this.klass}`); } } export function instanceOf(klass: Constructor): InstanceOf { return new InstanceOf(klass); }