microsoft / microsoft/TypeScript
Experiment with always using parameters from base types for derived methods
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ả
Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373.
Goal
We want to make it easier for users to derive types without rewriting the same parameter signature every time
class Base {
method(x: number) {
// ...
}
}
class Derived extends Base {
method(x) {
// 'x' should have the type 'number' here.
}
}
Potential ideas
- Only enable in
noImplicitAny(doesn't work for default initializers 😞) - Revert to
anyin all locations, opt in with another strictness flag (😞) - Something else? 😕
Potential issues
Default initializers with more capable derived types
class A {
a = 1;
}
class B extends A {
b = 2;
}
class Base {
method(x: A) {
// ...
}
}
class Derived extends Base {
method(x = new B) {
x.b;
// Today, 'x' has type 'B' which is technically unsound
// but that's just what we do. Does changing this to 'A' break things?
}
}
Default initializers that become less-capable via contextual types
class Base {
method(x: "a" | "b") {
// ...
}
}
class Derived extends Base {
method(x = "a") {
// We have to make sure 'x' doesn't have type '"a"'
// which is both unsound and less useful.
}
}
Distinction between properties and methods
Would this work?
class Base {
method = (x: number) => {
// ...
}
}
class Derived extends Base {
method(x) {
// Does 'x' have the type 'number' here?
}
}
What about this?
class Base {
method(x: number) {
// ...
}
}
class Derived extends Base {
method = (x) => {
// Does 'x' have the type 'number' here?
}
}
Keywords: base type derived contextual contextually inherit methods implicit any
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 mục tiêu và các ví dụ trong issue này, sau đó so sánh các issue liên quan đến property #3667, #6118 và #1373. Điều tra cách các derived methods, default initializers và method properties nên được contextualized; hoàn thành có nghĩa là các hệ quả đối với behavior và strictness đã được giải quyết cho tất cả các ví dụ.
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
- Tính năng
- Độ 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
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100