I'm looking for a way to pass on the typings of a parent's constructor parameters into the child's constructor, e.g.
class B extends A {
constructor (input) {
super(input);
}
}
I tried
class B extends A {
constructor (input : ConstructorParameters<typeof super>) {
super(input);
}
}
But I get an error from eslint 'super' is not defined.
I think you have to pass as ConstructorParameters<typeof A>[0] as a constructor param type.
class A {
title: string;
constructor(title: string) {
this.title = title;
}
}
class B extends A {
constructor(title: ConstructorParameters<typeof A>[0]) {
super(title);
}
}
One more solution you can try suggested in comment:
constructor(title: ConstructorParameters<typeof A>) {
super(...title);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With