microsoft / microsoft/TypeScript
Type argument with a subset of the parameter constraint's optional keys incorrectly reported as unassignable to constraint
Chưa có ai nhận issue này.
- 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
"does not satisfy the constraint" "keyof" "optional"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "constraint"
⏯ Playground Link
💻 Code
type MyType<T, U extends { [K in keyof T]?: unknown }> = U;
class MyClass<T> {
value!: MyType<T, { [K in keyof T & string]?: unknown }>;
}
🙁 Actual behavior
The following error is reported:
Type '{ [K in keyof T & string]?: unknown; }' does not satisfy the constraint '{ [K in keyof T]?: unknown; }'.
Type 'keyof T' is not assignable to type 'keyof T & string'.
Type 'string | number | symbol' is not assignable to type 'keyof T & string'.
Type 'string' is not assignable to type 'keyof T & string'.
Type 'string' is not assignable to type 'keyof T'.
Type 'keyof T' is not assignable to type 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
🙂 Expected behavior
No error should be reported because due to the keys being optional, { [K in keyof T & string]?: unknown } is a subtype of { [K in keyof T]?: unknown } for all T.
Additional information about the issue
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện chẩn đoán từ ví dụ TypeScript Playground được liên kết, sau đó truy vết quá trình kiểm tra ràng buộc generic cho các kiểu mapped có thuộc tính tùy chọn và intersected keyof keys. Công việc hoàn tất khi ví dụ biên dịch không có lỗi mà vẫn duy trì việc kiểm tra ràng buộc chính xác cho các trường hợp liên quan.
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
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100