{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13432","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13432/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13432/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13432/events","html_url":"https://github.com/Microsoft/TypeScript/issues/13432","id":200331989,"number":13432,"title":"BUG: getters, setters and inheritance","user":{"login":"endel","id":130494,"avatar_url":"https://avatars.githubusercontent.com/u/130494?v=3","gravatar_id":"","url":"https://api.github.com/users/endel","html_url":"https://github.com/endel","followers_url":"https://api.github.com/users/endel/followers","following_url":"https://api.github.com/users/endel/following{/other_user}","gists_url":"https://api.github.com/users/endel/gists{/gist_id}","starred_url":"https://api.github.com/users/endel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endel/subscriptions","organizations_url":"https://api.github.com/users/endel/orgs","repos_url":"https://api.github.com/users/endel/repos","events_url":"https://api.github.com/users/endel/events{/privacy}","received_events_url":"https://api.github.com/users/endel/received_events","type":"User","site_admin":false},"labels":[{"id":371615203,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Working%20as%20Intended","name":"Working as Intended","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-01-12T10:35:36Z","updated_at":"2017-01-25T21:19:09Z","closed_at":"2017-01-13T17:15:44Z","body":"<!-- BUGS: Please use this template. -->\r\n<!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:**  2.1.4\r\n\r\n**Code**\r\n\r\n```ts\r\nclass Base {\r\n    _height: number;\r\n    public set height (value: number) {\r\n        this._height = value;\r\n    }\r\n}\r\n\r\nclass Intermediary extends Base {\r\n    public get height () {\r\n        return this._height;\r\n    }\r\n}\r\n\r\nclass Concrete extends Intermediary {\r\n    constructor () {\r\n        super();\r\n        this.height = 10;\r\n    }\r\n}\r\n\r\nlet c = new Concrete();\r\nconsole.log(c.height);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nShould output `10`.\r\n\r\n**Actual behavior:**\r\n\r\n- TypeScript error:  `\"Cannot assign to 'height' because it is a constant or a read-only property.\"`\r\n- Generated JavaScript file outputs `undefined`.\r\n\r\nThe problem here is that the `Intermediary` class is overwriting the `set` method. I've changed the output `.js` file to fix this issue, and it looked like this: (using `getOwnPropertyDescriptor` on parent's prototype to keep the `set` reference.)\r\n\r\n```javascript\r\nvar Intermediary = (function (_super) {\r\n    __extends(Intermediary, _super);\r\n    function Intermediary() {\r\n        return _super.apply(this, arguments) || this;\r\n    }\r\n    Object.defineProperty(Intermediary.prototype, \"height\", {\r\n        set: Object.getOwnPropertyDescriptor(_super.prototype, \"height\").set,\r\n        get: function () {\r\n            return this._height;\r\n        },\r\n        enumerable: true,\r\n        configurable: true\r\n    });\r\n    return Intermediary;\r\n}(Base));\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/275236034","html_url":"https://github.com/Microsoft/TypeScript/issues/13432#issuecomment-275236034","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/13432","id":275236034,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2017-01-25T21:19:09Z","updated_at":"2017-01-25T21:19:09Z","body":"> This current behavior is inconsistent with how typescript otherwise behaves. \r\n\r\nI do not see why this is the case.\r\n\r\n> Could we at least get a compiler error or a warning? \r\n\r\nIssue https://github.com/Microsoft/TypeScript/issues/11596 tracks making this an error.\r\n\r\n"}}
{"actor":{"display_login":"mhegazy"}}