microsoft / microsoft/TypeScript
Overriden class member annotated with a subtype could be a recipe for disaster (by design.. ;) )
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling and running the TypeScript example in the issue, then read the discussion about the intended inheritance behavior. A viable contribution would need an agreed language design, an implementation plan, and regression coverage showing the resulting behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100