microsoft / microsoft/TypeScript
Object is possibly undefined after undefined check on readonly property
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ả
TypeScript Version: 3.7.4, 3.9.2
Search Terms:
Object is possibly undefined
undefined readonly callback
Code
class Test {
private readonly testProperty?: { value: number };
public constructor(testProperty: { value: number }) {
this.testProperty = testProperty;
}
public method() {
if (this.testProperty) {
Promise.resolve().then(() => this.testProperty.value); //Object is possibly undefined
}
}
}
Expected behavior:
testProperty should not be resolved as possibly undefined as this is not possible in this scenario as the property has already been checked and it is marked as readonly.
Actual behavior:
testProperty is possibly undefined, requiring another undefined check.
Related Issues:
Similar issues but these i understand why TypeScript would report an error, in my case the property is readonly so it seems like a bug to me.
https://github.com/microsoft/TypeScript/issues/38053
https://github.com/microsoft/TypeScript/issues/11498
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 bản tái hiện được liên kết trong Playground và so sánh hành vi được mô tả trong các issue liên quan #38053 và #11498. Theo dõi việc kiểm tra kiểu cho readonly optional property bên trong callback của Promise; hoàn tất khi ví dụ được cung cấp không còn báo cáo “possibly undefined” hoặc hành vi mong đợi được giải quyết theo cách khác.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- 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
- 35/100