microsoft / microsoft/TypeScript
ReturnType is lost after a simple wrapper function
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 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_
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 CodeSandbox 中的复现开始,尤其检查 /src/services/pokemon.ts,并比较直接查询钩子及其包装器推断出的类型。运行示例并检查 data2 为什么会变成 any;当包装器保留被包装钩子的推断返回类型时即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- redux, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100