microsoft / microsoft/TypeScript

ReturnType is lost after a simple wrapper function

Đang mở
#61,780 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Needs More Info
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

### 🔎 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_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng việc tái hiện trong CodeSandbox được liên kết, đặc biệt là /src/services/pokemon.ts, và so sánh các kiểu được suy luận từ query hook trực tiếp và wrapper của nó. Chạy ví dụ và kiểm tra lý do data2 trở thành any; hoàn tất khi wrapper giữ nguyên kiểu giá trị trả về được suy luận của hook được bọc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
redux, typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.