Missing error when mistyped value overwrites property of spreaded generic type parameter
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu với ví dụ Playground được liên kết và so sánh trường hợp spread generic với các trường hợp non-generic và non-spread được nêu trong báo cáo. Theo dõi hành vi kiểm tra kiểu đối với phép gán value: 123 trong spread đối tượng generic, và xem issue là hoàn tất khi TypeScript báo cáo tính không tương thích như mong đợi mà không gây hồi quy cho các ví dụ khác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
🔎 Search Terms
generic argument, rest spread, false positive
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about object spread and generics
I found a few relevant issues, but none of them fully correspond to the current one:
- https://github.com/microsoft/TypeScript/issues/35858
- https://github.com/microsoft/TypeScript/issues/38469
- https://github.com/microsoft/TypeScript/issues/30129
⏯ Playground Link
Playground link with relevant code
💻 Code
interface InputProps {
value: string;
}
const getProps = (props: InputProps): InputProps => ({
...props,
value: 123, // when there is no generic type, it shows an error, as expected
});
const getPropsGenericNoSpead = <T extends InputProps>(props: T): T => {
const newProps = {...props};
newProps.value = 123; // also error, as expected
return newProps;
};
const getPropsGeneric = <T extends InputProps>(props: T): T => ({
...props,
value: 123, // no error here
});
🙁 Actual behavior
Typescript allows assigning incompatible types
🙂 Expected behavior
Typescript shows an error
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 106
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.
Issue khác của microsoft/TypeScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64322 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Possible Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/TypeScript#64278 · 1 bình luận · 1 reaction ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/TypeScript#64118 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64094 ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TypeScript#63959 · 5 bình luận ·
Tất cả issue của microsoft/TypeScript
Issue tương tự
-
Type/Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenNSW/nsw-srilanka#497 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
kubernetes-sigs/prow#953 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
caddyserver/caddy#8046 ·