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

Problem with generic type with custom-fetch #1743

Closed
camillecroci opened this issue Dec 12, 2024 · 0 comments · Fixed by #1768
Closed

Problem with generic type with custom-fetch #1743

camillecroci opened this issue Dec 12, 2024 · 0 comments · Fixed by #1768
Labels
fetch Fetch client related issue
Milestone

Comments

@camillecroci
Copy link

What are the steps to reproduce this issue?

  1. Create a custom fetch similar to the example in next-app-with-fetch sample
  2. Generates code, or look at the generated code from the sample
export const listPets = async (
  params?: ListPetsParams,
  options?: RequestInit,
): Promise<listPetsResponse> => {
  return customFetch<Promise<listPetsResponse>>(getListPetsUrl(params), {
    ...options,
    method: 'GET',
  });
};
  1. Look at the type passed for the customFetch in the generated code. If you have vscode, you can hover on your generated function to see the return type of it.

What happens?

Custom-fetch receives a Promise<listPetsResponse> in place of the generic T.

What were you expecting to happen?

Only to pass listPetsResponse in place of the generic T. Custom-fetch has to await so its expected signature will be Promise<T>. If you pass Promise<listPetsResponse>, you end up with functions that have returned type Promise<Promise>`

Any logs, error output, etc?

No errors, I think it is just incorrect in term of type.

What versions are you using?

  System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M1
    Memory: 76.56 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  npmPackages:
    msw: ^2.6.5 => 2.6.5 
    orval: ^7.1.1 => 7.1.1 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetch Fetch client related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants