Missing error when mistyped value overwrites property of spreaded generic type parameter

Đang mở
#42,690 6 bình luận 13 reaction 0 người được giao Xem trên GitHub

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

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:

⏯ 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

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.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

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.