microsoft / microsoft/TypeScript

`Parameters` returns `never` when used with a generic function that combines `Pick` and `Partial` on the generic type argument

Đang mở
#61,516 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Domain: check: Type Inference Help Wanted
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

partial pick generic parameters never

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Parameters
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250331#code/C4TwDgpgBA8gRgKygXgFBSgHygbyqSALigHIBDEgGigEsATYgZ2ACcaA7Ac2rKdY85QAvuiy584CMRJwqtBlGZsu1OMXYBXALZwILYQG5UqDsD0AzMgGNoAQQAKASVyiA7gHsWAa0YAeACpQEAAeZux0jLCIAHwAFKIY7ojE-pSiAJTEAG7u9EaiZAA2jO4A6p4+AUGhEOGR8AhxCVBJCMT2NFZeAdQkBBAkYiT0JNFpGJlQOXnGGEUltsVlFX6BIWERUY3xGInJUPZkLMA0RQHRGdm5dPkYdO4QjOzA5d5V67WbDU27LfsdXR6pH6g2wwzooygADIDkcTmd-BcJlcZiJUP0oK8fIcWGQtJFkLDcVoIGYWH4HI4ANokDzeRgkAC60QMvzZ7IwAHpOVAqa1iA1GejJFBFiUsYwcXiCUS8aS9BSnDT5st6UyWRyuTy+f9Ot0GtQAET9Q1iQ30Q3RIUYsXuW0SqX4lCyklkxXU8hLe0rdWs7m8-lE+GFXzfa0igAiDyeLwqjpljvl5N8lJp90ezyxvo5-vYECyeiAA

💻 Code
type Obj =
  | { type: 'a', id: string, a: string }
  | { type: 'b', id: string, b: number };

interface API {
  works<T extends Obj>(
    obj: T,
  ): void;

  alsoWorks<T extends Obj>(
    obj: Pick<T, 'type' | 'id'>,
  ): void;

  alsoAlsoWorks<T extends Obj>(
    obj: Partial<T>
  ): void;

  doesntWork<T extends Obj>(
    obj: Pick<T, 'type' | 'id'> & Partial<T>
  ): void;
}

type WorksParams = Parameters<API['works']>;                 // [obj: Obj]
type AlsoWorksParams = Parameters<API['alsoWorks']>;         // [obj: Pick<Obj, "type" | "id">]
type AlsoAlsoWorksParams = Parameters<API['alsoAlsoWorks']>; // [obj: Partial<Obj>]
type DoesntWorkParams = Parameters<API['doesntWork']>;       // never
🙁 Actual behavior

Parameters<API['doesntWork']> returns never

🙂 Expected behavior

The Parameters<API['doesntWork']> case behaves like the other cases and returns [obj: Pick<Obj, "type" | "id"> & Partial<Obj>].

Additional information about the issue

I'm not sure why Parameters works for all cases except when Pick and Partial are used together. I'm having the same problem when using extends and infer to get the parameters.

My use case is to prepend an argument event: IpcMainInvokeEvent to several generic functions to match the signature expected by the listener argument of Electron's ipcMain.handle method. If anyone knows of a workaround for this Parameters problem, I'd love to hear it.

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

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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với TypeScript Playground được liên kết và rút gọn ví dụ API liên quan đến Pick<T, 'type' | 'id'> & Partial. So sánh kết quả của Parameters cho bốn phương thức và truy tìm hành vi liên quan của việc suy luận kiểu. Được xem là hoàn tất khi trường hợp kết hợp Pick và Partial tạo ra tuple tham số như mong đợi mà không gây hồi quy cho các trường hợp khá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ệ
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
45/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.