{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8474","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8474/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8474/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8474/events","html_url":"https://github.com/Microsoft/TypeScript/issues/8474","id":153242372,"number":8474,"title":"Overriden class member annotated with a subtype could be a recipe for disaster (by design.. ;) )","user":{"login":"malibuzios","id":17719551,"avatar_url":"https://avatars.githubusercontent.com/u/17719551?v=3","gravatar_id":"","url":"https://api.github.com/users/malibuzios","html_url":"https://github.com/malibuzios","followers_url":"https://api.github.com/users/malibuzios/followers","following_url":"https://api.github.com/users/malibuzios/following{/other_user}","gists_url":"https://api.github.com/users/malibuzios/gists{/gist_id}","starred_url":"https://api.github.com/users/malibuzios/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malibuzios/subscriptions","organizations_url":"https://api.github.com/users/malibuzios/orgs","repos_url":"https://api.github.com/users/malibuzios/repos","events_url":"https://api.github.com/users/malibuzios/events{/privacy}","received_events_url":"https://api.github.com/users/malibuzios/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-05T14:21:28Z","updated_at":"2016-05-05T16:59:33Z","closed_at":null,"body":"**TypeScript Version:** \r\n`1.9.0-dev.20160505` with both `strictNullChecks` and `noImplicitAny` enabled.\r\n\r\n**Code:**\r\n\r\n```ts\r\nclass Animal {\r\n    name: string = \"Any animal\";\r\n}\r\n\r\nclass Dog extends Animal {\r\n    name: string = \"Dog\";\r\n\r\n    bark() {\r\n        console.log(\"bark\");\r\n    }\r\n}\r\n\r\nclass AnimalCage {\r\n    member: Animal = new Animal();\r\n}\r\n\r\nclass DogCage extends AnimalCage {\r\n    member: Dog;\r\n}\r\n\r\nlet dogCage = new DogCage();\r\n\r\nif (dogCage.member != null) { // Yup, it is even checked for null or undefined, \r\n\t\t\t\t\t\t\t  // but it turned out that wasn't enough..\r\n    dogCage.member.bark(); // Bang!\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nDesign a language where inheritance actually works.\r\n(_Edit: I was felling very 'passionate' when I wrote this.. sorry :) nothing personal_)\r\n\r\n**Actual behavior:** \r\nBy design:\r\n```\r\n    dogCage.member.bark();\r\n                   ^\r\n\r\nTypeError: dogCage.member.bark is not a function\r\n    at Object.<anonymous> (C:\\X\\Documents\\Drafts\\TypeScript\\Code\\a.js:38:20)\r\n    at Module._compile (module.js:541:32)\r\n    at Object.Module._extensions..js (module.js:550:10)\r\n    at Module.load (module.js:456:32)\r\n    at tryModuleLoad (module.js:415:12)\r\n    at Function.Module._load (module.js:407:3)\r\n    at Function.Module.runMain (module.js:575:10)\r\n    at startup (node.js:159:18)\r\n    at node.js:444:3\r\n```\r\n\r\n**Resolution:**\r\n`tslint` volunteers, for the rescue!"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/217210536","html_url":"https://github.com/Microsoft/TypeScript/issues/8474#issuecomment-217210536","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8474","id":217210536,"user":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T16:59:33Z","updated_at":"2016-05-05T16:59:33Z","body":"This certainly isn't desirable behavior.\r\n\r\nThat said, I'm not sure how we could detect this reliably. For example, if `AnimalCage` came from a .d.ts file, we have no idea if it was initialized or not (though I suppose with `--strictNullChecks` on, we have to assume it was). Without having covariance annotations I don't think there's a possible fix that covers all cases, but I'm open to ideas if you have any."}}