microsoft / microsoft/TypeScript

Unable to infer parameters for generic constructor/functions with a distributive conditional type

Đang mở
#62,079 1 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: Conditional Types 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

generic constructor, generic function, branded string, `ConstructorParameters`, `Parameters`, unable to infer.

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAbwL4G4CwAoTBLAdjYKAMwEMBjYOAfQFkSxFM44iIIAuROEzgRgCYAzHCSZRWDDACeYSjQgATAK4AbYAGUlAIwAqMygF44AIi0koxuADIuWqCVwLOMKEsqpMmabLh0GR2nprOAAlYDJoBQAeeWU1TV19ABpbFRIAC04AZxc8AHMRAD5PSX04BL1ZAHFgGCimcu1KylACRyy4HKh8pIa-OFbgdtDwyKiK5LglXABrXAgAd1xC3oxCuCMJn0Hh6bnF3EwAfi5vYCPOLfdgvwBtK4BdTE5cYAA3QnQJAHpvuB10tgOkC4DB0pQALYQHKdFwkbB5dIwVhQBbmBRwNFSOAASTgZAcLARSiglAgSngMAg+IgEMoVNBgOBWSybnYXjKOmAOQACuYSHSCFAOkY+fZBYQslEojoBiA2goOsZWBBLAAfXyKVQaJr6QoACnMeUuuuqtRlKT8hQAlBt1m8INgFMUML9mHAAHonV4fKAlN146AIvAkFQqbFDCLTIXADHYeALePpbj4tIsuAqbAzelM9kYBThNKk1MkdNcnIyuUKpUq9WauI6xKydYIBoRXBdJRkKlQQ1QY2NJvAGp1HSW+g2r7iDk+cswADCEA7Li7PbFAtqko2cEXy9c3eg64lwqiZwgRH+3JghS+buYXrgPsIQA

### 💻 Code

```ts
export {};

interface _Map {
foo: { a: 123 }
}

type ModuleSubType = "bar" & { brand: true };

type Map = _Map & Record

type SubTypeGet<
SubType extends string,
Map extends Record,
> = SubType extends unknown
? { type?: SubType } & Map[SubType]
: never;

// This is the most straightforward way I can figure out to come to this issue:
type TestParameters = Parameters<(arg: SubTypeGet) => void>
// ^? never

// I originally encountered it with a class like this:
declare class Test {
constructor(arg: SubTypeGet);
}

type TestConstructorParameters = ConstructorParameters;
// ^? never
```

### 🙁 Actual behavior

`Parameters` fails to infer anything.

### 🙂 Expected behavior

`Parameters` should infer _something,_ probably `[arg: { type?: ModuleSubType | undefined; } | ({ type?: "foo" | undefined; } & { a: 123; })]` as it would if the function/class were instantiated.

### Additional information about the issue

_No response_

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

Sử dụng bản tái hiện Playground được liên kết làm điểm bắt đầu đầu tiên; kiểm tra cách các kiểu điều kiện phân phối truyền qua Parameters và ConstructorParameters trong các ví dụ về hàm generic và constructor. Được xem là hoàn tất khi cả hai tiện ích đều suy luận một tuple tham số khác never, phù hợp với hành vi mong đợi, và bản tái hiện hiện có không còn thất bại.

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ó
5/5
Thời gian dự kiến
Hơn một tuần
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
35/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.