Here is a minimal reproducible example of your problem:
class Super {
static hello(): void {
console.log('hello');
}
}
class SubA extends Super {
constructor(arg: string) { super(); }
}
class SubB extends Super {
constructor(arg: string) { super(); }
}
function saySomething(cls: typeof Super) {
cls.hello()
}
// turn out
// Argument of type 'typeof SubA' is not assignable to parameter of type 'typeof Super'.
// with vscode
saySomething(SubA);
saySomething(SubB);
TypeScript playground
The problem occurs because a constructor function of an extending class doesn't necessarily take the same arguments, so it's not assignable to the Super
class constructor.
As you don't need the constructor function at all but only the static
properties (attached to the constructor), you could use a NoConstructor
helper type in order to keep only the keys and remove the constructor function from the typeof Super
type:
class Super {
static hello(): void {
console.log('hello');
}
}
class SubA extends Super {
constructor(arg: string) { super(); }
}
class SubB extends Super {
constructor(arg: string) { super(); }
}
type NoConstructor<T> = Pick<T, keyof T>;
function saySomething(cls: NoConstructor<typeof Super>) {
cls.hello(); // Works
}
saySomething(SubA); // Works
saySomething(SubB); // Works
TypeScript playground