microsoft / microsoft/TypeScript
T.constructor should be of type T
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
Given
class Example {
}
The current type of Example.constructor is Function, but I feel that it should be typeof Example instead. The use case for this is as follows:
I'd like to reference the current value of an overridden static property on the current class.
In TypeScript v1.5-beta, doing this requires:
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
(<typeof Example>this.constructor).someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
(<typeof SubExample>this.constructor).someProperty
);
}
}
After this proposal, the above block could be shortened to:
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
this.constructor.someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
this.constructor.someProperty
);
}
}
This removes a cast to the current class.
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
Sử dụng hai ví dụ về class trong issue làm điểm khởi đầu về hành vi, sau đó lần theo các quy tắc kiểm tra kiểu của TypeScript đối với constructor của instance và các thành viên static. Được xem là hoàn tất khi các truy cập this.constructor được đề xuất vượt qua kiểm tra kiểu mà không cần các casts được minh họa, đồng thời vẫn giữ nguyên hành vi dự kiến cho các subclass.
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
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100