Reputation: 2370
Is it possible to do something like this? It would help quite a lot. Us the method signature from generics
class Foo<Parent extends Foo> {
public bar<U extends Parameters<Parent.bar>>(x: U) {
}
}
Upvotes: 0
Views: 48
Reputation: 249476
You can't if you want Parent
to extend Foo
, since that would cause a circular dependency in the type, but you can do it if you constrain Parent
to something else with a bar
:
class Foo<Parent extends { bar: (...a: any[]) => any}> {
public bar<U extends Parameters<Parent['bar']>>(x: U) {
}
}
You might also be interested in this version that spreads the arguments back to the bar
function:
class Foo<Parent extends { bar: (...a: any[]) => any}> {
public bar(...x: Parameters<Parent['bar']>) {
}
}
Upvotes: 1