microsoft / microsoft/TypeScript
strictFunctionTypes prevents an assignment not related to functions
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: 3.3.0-dev.20181122
Search Terms:
covariance, contravariance, keyof, interface, class, generic
Code
interface IBase {
foo: string;
}
interface IDerived extends IBase {
bar: string;
}
type StringPropertyNames<T> = { [P in keyof T]: T[P] extends string ? P : never }[keyof T]
type StringProperties<T> = Pick<T, StringPropertyNames<T>>
interface Foo<T> {
readonly Bar: StringProperties<T>;
}
let baseProperties: StringProperties<IBase>
let derivedProperties: StringProperties<IDerived>
let baseInterface: Foo<IBase>
let derivedInterface: Foo<IDerived>
baseProperties = derivedProperties // no error
baseInterface = derivedInterface
tsc test.ts --strictFunctionTypes
Expected behavior:
Compiles without errors.
Actual behavior:
test.ts:23:1 - error TS2322: Type 'Foo<IDerived>' is not assignable to type 'Foo<IBase>'.
Property 'bar' is missing in type 'IBase' but required in type 'IDerived'.
23 baseInterface = derivedInterface
~~~~~~~~~~~~~
test.ts:6:5
6 bar: string;
~~~
'bar' is declared here.
Related Issues:
#24190
The documentation says:
Under --strictFunctionTypes function type parameter positions are checked contravariantly instead of bivariantly.
I couldn't find any information saying it should affect anything else.
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 ví dụ được cung cấp trong test.ts bằng tsc test.ts --strictFunctionTypes, rồi so sánh hai kết quả phép gán. Payload không nêu tên tệp triển khai hoặc bài kiểm thử hồi quy nào, vì vậy hãy lần theo đường đi của quá trình kiểm tra kiểu đối với phép gán kiểu ánh xạ generic được báo cáo. Hoàn thành khi hành vi phép gán được báo cáo khớp với kết quả mong đợi mà không gây hồi quy trong việc kiểm tra nghiêm ngặt tham số hàm.
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
- 28/100