microsoft / microsoft/TypeScript
ReturnType is lost after a simple wrapper function
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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 _______
### ⏯ Playground Link
https://codesandbox.io/p/devbox/lingering-fog-5fhtrv
### 💻 Code
```ts
const { useGetPokemonByNameQuery } = pokemonApi;
// Wrapper to demonstrate the issue
export const useGetPokemonByNameQueryWrapper = (
...parameters: Parameters
) => {
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_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione nel CodeSandbox collegato, in particolare in /src/services/pokemon.ts, e confronta i tipi inferiti del hook di query diretto e del relativo wrapper. Esegui l'esempio e verifica perché data2 diventa any; il lavoro è completato quando il wrapper mantiene il tipo di ritorno inferito dell'hook avvolto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- redux, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100