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

Create F.MapAwaitedReturnType fn #120

Open
ThomasAribart opened this issue Aug 20, 2024 · 2 comments
Open

Create F.MapAwaitedReturnType fn #120

ThomasAribart opened this issue Aug 20, 2024 · 2 comments

Comments

@ThomasAribart
Copy link

ThomasAribart commented Aug 20, 2024

F.MapReturnType works correctly but it does not apply on async functions. I suggest creating a F.MapAwaitedReturnType function:

export type MapAwaitedReturnType<
  FN extends Fn | unset | _ = unset,
  ASYNC_FUNCTION extends ((...args: any[]) => Promise<any>) | _ | unset = unset,
> = PartialApply<MapAwaitedReturnTypeFn, [FN, ASYNC_FUNCTION]>

interface MapAwaitedReturnTypeFn extends Fn {
  return: this['args'] extends [infer FN extends Fn, infer ASYNC_FUNCTION]
    ? ASYNC_FUNCTION extends (...params: infer PARAMS) => Promise<infer RETURN_TYPE>
      ? (...params: PARAMS) => Promise<Call<FN, RETURN_TYPE>>
      : never
    : never
}

@gvergnaud I can create the PR if you want!

@gvergnaud
Copy link
Owner

I think I'd prefer having a Promises module that has a map function:

type X = H.Functions.MapReturnType<H.Promises.Map<Fn>>

That seems more powerful because Promises.Map could be composed in other ways too. WDYT?

@ThomasAribart
Copy link
Author

Yes, I agree 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants