Issue
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.
Solution
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);
}
Answered By - Rahul Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.