Skip to content

Create F.MapAwaitedReturnType fn #120

Description

@ThomasAribart

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions