microsoft / microsoft/TypeScript
ReturnType is lost after a simple wrapper function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
### 🔎 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_
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Reproduktion im verlinkten CodeSandbox, insbesondere mit /src/services/pokemon.ts, und vergleiche die abgeleiteten Typen des direkten Query-Hooks und seines Wrappers. Führe das Beispiel aus und untersuche, warum data2 zu any wird; abgeschlossen ist die Aufgabe, wenn der Wrapper den abgeleiteten Rückgabetyp des umschlossenen Hooks beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- redux, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100