Open hackape opened 3 years ago
This doesn't work for object destructured assignment:
type AbstractConstructorParameters<T> = ConstructorParameters<(new (...args: any) => any) & T>;
abstract class Test {
constructor ({
a,
b
}: {
a: string,
b: string
}) {
console.log(a);
}
}
class Test2 extends Test {
constructor (
{
c: string,
...rest
}: {
c: string;
rest: AbstractConstructorParameters<typeof Test>
}
) {
super(...rest);
}
}
Is your feature request related to a real problem or use-case?
Utility type to get constructor params from abstract class. TS built-in
ConstructorParameters
does not work on abstract class type since it's not constructible.Describe a solution including usage in code example
Solution:
Usage:
Who does this impact? Who is this for?
Typescript user, generally useful in OOP.
Credit
Found this workaround here, which in turn refers to this reddit post by u/adamuso