-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Following up on #5236 (comment), the proposed solution doesn't cover all bases now that abstract classes are supported.
abstract class A {}
class B extends A {}
function isType<T>(value: any, key: { new(...args: any[]): T }): boolean {
return value instanceof key;
}
console.log(isType((new B), A))Error TS2345: Argument of type 'typeof A' is not assignable to parameter of type 'new (...args: any[]) => A'. Cannot assign an abstract constructor type to a non-abstract constructor type.
On a related note, interfaces and abstract classes feel a bit kludgey since I can't seem to verify that an arbitrary object actually conforms to them. I can require them as parameter types and use user-defined type guards, but there's no generic equivalent to instanceof.
thorn0, Artazor, radarsu, unional, RodrigoQuesadaDev and 9 more
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug