function isSameOrSubclass<T>(target:any,reference:typeof T):target is T
{
const targetIsReference = target===reference,
targetIsTruthy = target&&true,
targetHasPrototype = "prototype" in target,
targetIsSubclass = targetIsTruthy&&targetHasPrototype&&(target.prototype instanceof reference)
return targetIsReference||targetIsSubclass;
}
Compiler fails with the following error:
TS2693: 'T' only refers to a type, but is being used as a value here.
Substituting typeof T with new()=>T allows compilation, but disallows this:
isSameOrSubclass<Class>(foo,Class)
because
Argument of type 'typeof Class' is not assignable to parameter of type 'new () => Class'.