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

Option to give useAsync the parameter types #333

Open
dcodesdev opened this issue Mar 5, 2024 · 0 comments
Open

Option to give useAsync the parameter types #333

dcodesdev opened this issue Mar 5, 2024 · 0 comments

Comments

@dcodesdev
Copy link

Right now all of the custom argument types that can be given to the promiseFn property are type of any.

Meaning when someone else tries to re-use your code, they can not know what types they should provide.

Example:

export const useJoinWaitlist = () => {
  return useAsync({
    promiseFn: ({ email }) =>
      getClient()
        .post<JoinWaitlistResponse>("/waitlist/join", { email })
        .then((r) => r.data),
  })
}

In this case, the type of email is of any

Suggetion

It would be nice to have the option to provide the argument types of the promiseFn

export const useJoinWaitlist = () => {
  type Args = {
    email: string
  }

  return useAsync<JoinWaitlistResponse, Args>({
    promiseFn: ({
      // Email type is now defined and is of type `string`
      email,
    }) =>
      getClient()
        .post<JoinWaitlistResponse>("/waitlist/join", { email })
        .then((r) => r.data),
  })
}
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

1 participant