microsoft / microsoft/TypeScript
Interface merging for any property names does not allow type narrowing
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
TypeScript Version: 4.1.0-dev.20201002
Search Terms: interface merging merge object any name subsequent property declarations
Code
interface PropsContainer {
props: {
[propName: string]: any;
}
}
interface PropsContainer {
props: {
[propName: string]: any;
specialProp: string;
}
}
Expected behavior:
This should be allowed. The merged interface should result in a type with props that have any prop name as any except for specialProp which is a string.
This would be useful in a case where a third party library (such as @types/react-test-renderer) declare an object type with { [propName: string]: any } syntax, but you want to narrow the value of the property for specific types via interface merging.
Note that even { specialProp?: any, [propName: string]: any } is not allowed even though the types are functionally identical in this case.
Actual behavior:
This results in a Subsequent property declarations must have the same type.
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
Bắt đầu với reproduction TypeScript Playground được liên kết và xác nhận diagnostic cho hai khai báo PropsContainer được hợp nhất. Sau đó, lần theo đường đi của quá trình kiểm tra kiểu cho các khai báo thuộc tính và index signature tiếp theo. Được xem là hoàn tất khi merge được hiển thị được chấp nhận, specialProp được thu hẹp thành string và các khai báo lại không tương thích hiện có vẫn bị từ chố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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100