type Ctor = { new(...args: any): any; }; export function castObject(value: unknown, ctor: O): InstanceType { if (value instanceof ctor) { return value; } throw new TypeError(`passed value "${String(value)}" is not instance of ${ctor.name}`); }