What problem is this solving
Currently, TypeScript generics have a design limitation which will block the capability to rewrite a generic function return type while providing its generic arguments. That's why a lot of enhancers/runners have dedicated "extension" properties and types, which allow us to have a correct defintion for action's method's typing for the enhancer/runner.
While the best way to do this is to have a generic method on actions, another simplier possiblity is to have a generic extension factory which will only take an enhancer/runner.
Proposed solution
Here is an example on the work I've already done on the question:
function makeEnhancerPlugin<Args extends any[], NC extends {}, C extends {}>(
enhancer: (...args: Args) => (action: Action<C>) => Awaitable<Action<NC>>,
) {
return function invoke(
this: Action<C>,
...args: Args
) {
return this.use(enhancer(...args)) as Action<NC>;
};
}
This solution is close to work, but currently it will only return an Action without any other custom methods.
Describe alternatives you've considered
No response
What problem is this solving
Currently, TypeScript generics have a design limitation which will block the capability to rewrite a generic function return type while providing its generic arguments. That's why a lot of enhancers/runners have dedicated "extension" properties and types, which allow us to have a correct defintion for action's method's typing for the enhancer/runner.
While the best way to do this is to have a generic method on actions, another simplier possiblity is to have a generic extension factory which will only take an enhancer/runner.
Proposed solution
Here is an example on the work I've already done on the question:
This solution is close to work, but currently it will only return an Action without any other custom methods.
Describe alternatives you've considered
No response