microsoft / microsoft/TypeScript
Overriden class member annotated with a subtype could be a recipe for disaster (by design.. ;) )
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
TypeScript Version:
1.9.0-dev.20160505 with both strictNullChecks and noImplicitAny enabled.
Code:
class Animal {
name: string = "Any animal";
}
class Dog extends Animal {
name: string = "Dog";
bark() {
console.log("bark");
}
}
class AnimalCage {
member: Animal = new Animal();
}
class DogCage extends AnimalCage {
member: Dog;
}
let dogCage = new DogCage();
if (dogCage.member != null) { // Yup, it is even checked for null or undefined,
// but it turned out that wasn't enough..
dogCage.member.bark(); // Bang!
}
Expected behavior:
Design a language where inheritance actually works.
(Edit: I was felling very 'passionate' when I wrote this.. sorry :) nothing personal)
Actual behavior:
By design:
dogCage.member.bark();
^
TypeError: dogCage.member.bark is not a function
at Object.<anonymous> (C:\X\Documents\Drafts\TypeScript\Code\a.js:38:20)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:159:18)
at node.js:444:3
Resolution:
tslint volunteers, for the rescue!
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 bằng cách biên dịch và chạy ví dụ TypeScript trong issue, sau đó đọc phần thảo luận về hành vi kế thừa được dự định. Một đóng góp khả thi sẽ cần một thiết kế ngôn ngữ đã được thống nhất, một kế hoạch triển khai và độ bao phủ hồi quy cho thấy hành vi thu đượ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
- 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
- 20/100