Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): provide a generic enhancer/runner extension factory #1

Open
paul-thebaud opened this issue Nov 3, 2023 · 0 comments
Open
Labels
priority:low May be addressed at any time scope:core @foscia/core status:external Depends on an external fix type:feat New feature

Comments

@paul-thebaud
Copy link
Contributor

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

@paul-thebaud paul-thebaud added type:feat New feature status:external Depends on an external fix priority:low May be addressed at any time scope:core @foscia/core labels Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:low May be addressed at any time scope:core @foscia/core status:external Depends on an external fix type:feat New feature
Projects
None yet
Development

No branches or pull requests

1 participant