Skip to content

ReturnType is lost after a simple wrapper function #61780

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

Open
alex-vukov opened this issue May 29, 2025 · 0 comments
Open

ReturnType is lost after a simple wrapper function #61780

alex-vukov opened this issue May 29, 2025 · 0 comments

Comments

@alex-vukov
Copy link

🔎 Search Terms

ReturnType changes to any, wrapper function losing inferred types

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about YES
  • I was unable to test this on prior versions because _______

⏄1�7 Playground Link

https://codesandbox.io/p/devbox/lingering-fog-5fhtrv

💻 Code

const { useGetPokemonByNameQuery } = pokemonApi;

// Wrapper to demonstrate the issue
export const useGetPokemonByNameQueryWrapper = (
  ...parameters: Parameters<typeof useGetPokemonByNameQuery>
) => {
  return useGetPokemonByNameQuery(...parameters);
};

const useTest = () => {
  // data1 has type Pokemon | undefined as expected
  const { data: data1 } = useGetPokemonByNameQuery("pikachu");

  // data2 has type any???
  const { data: data2 } = useGetPokemonByNameQueryWrapper("pikachu");
};

🙁 Actual behavior

When I wrap any query hook generated by Redux Toolkit Query with any simple wrapper function the return type stops being inferred and changes to 'any'. Check the example in the attached Sandbox in file /src/services/pokemon.ts

🙂 Expected behavior

I expect the wrapper function to preserve the return type of the wrapped function and to correctly infer it.

Additional information about the issue

No response

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