export type AnyClass = new (...params: any[]) => unknown; export interface AnyInstance { constructor?: AnyClass; } export function instanceOf(maybeInstance: unknown, Type: T): maybeInstance is InstanceType { return ( maybeInstance instanceof Type || (!!maybeInstance && !!(maybeInstance as AnyInstance).constructor && (maybeInstance as AnyInstance).constructor!.name === Type.name) ); }