{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7574","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7574/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7574/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7574/events","html_url":"https://github.com/Microsoft/TypeScript/issues/7574","id":141764917,"number":7574,"title":"Return value of super() calls not used for `this`","user":{"login":"justinfagnani","id":522948,"avatar_url":"https://avatars.githubusercontent.com/u/522948?v=3","gravatar_id":"","url":"https://api.github.com/users/justinfagnani","html_url":"https://github.com/justinfagnani","followers_url":"https://api.github.com/users/justinfagnani/followers","following_url":"https://api.github.com/users/justinfagnani/following{/other_user}","gists_url":"https://api.github.com/users/justinfagnani/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfagnani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfagnani/subscriptions","organizations_url":"https://api.github.com/users/justinfagnani/orgs","repos_url":"https://api.github.com/users/justinfagnani/repos","events_url":"https://api.github.com/users/justinfagnani/events{/privacy}","received_events_url":"https://api.github.com/users/justinfagnani/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/ES6","name":"ES6","color":"c7def8"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-03-18T03:35:22Z","updated_at":"2016-09-04T03:14:59Z","closed_at":null,"body":"If a constructor returns a value other than `this`, then in subclasses `super()` calls to that constructor should use the result as `this` in the subclass constructor.\r\n\r\nI believe this is specified in 12.3.5.1, step 10 of SuperCall: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-super-keyword\r\n\r\nGetting this behavior correct is going to be very important for supporting Custom Elements, which takes advantage of this to initialize browser-allocated elements with user-written constructors. See https://w3c.github.io/webcomponents/spec/custom/#htmlelement-constructor\r\n\r\nNote, Babel 6 implements this correctly.\r\n\r\n**TypeScript Version:** \r\n\r\n1.8.9\r\n\r\n**Code**\r\n\r\n```ts\r\nclass Foo {\r\n\r\n  x : number;\r\n\r\n  constructor() {\r\n    return {\r\n      x: 1,\r\n    };\r\n  }\r\n}\r\n\r\nclass Bar extends Foo {\r\n\r\n  y : number;\r\n\r\n  constructor() {\r\n    super();\r\n    this.y = 2;\r\n  }\r\n}\r\n\r\nlet o = new Bar();\r\nconsole.assert(o.x === 1 && o.y === 2);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo assertion error\r\n\r\nThe constructor for `Bar` should compile to this:\r\n\r\n```javascript\r\nvar Bar = (function (_super) {\r\n    __extends(Bar, _super);\r\n    function Bar() {\r\n        var _this = _super.call(this);\r\n        _this.x = 1;\r\n        return _this;\r\n    }\r\n    return Bar;\r\n}(Foo));\r\n```\r\n\r\n**Actual behavior:** \r\n\r\nAssertion error\r\n\r\nThe constructor for Bar compiles to this:\r\n\r\n```javascript\r\nvar Bar = (function (_super) {\r\n    __extends(Bar, _super);\r\n    function Bar() {\r\n        _super.call(this);\r\n        this.x = 1;\r\n    }\r\n    return Bar;\r\n}(Foo));\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/244581896","html_url":"https://github.com/Microsoft/TypeScript/issues/7574#issuecomment-244581896","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/7574","id":244581896,"user":{"login":"Arnavion","id":1096010,"avatar_url":"https://avatars.githubusercontent.com/u/1096010?v=3","gravatar_id":"","url":"https://api.github.com/users/Arnavion","html_url":"https://github.com/Arnavion","followers_url":"https://api.github.com/users/Arnavion/followers","following_url":"https://api.github.com/users/Arnavion/following{/other_user}","gists_url":"https://api.github.com/users/Arnavion/gists{/gist_id}","starred_url":"https://api.github.com/users/Arnavion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arnavion/subscriptions","organizations_url":"https://api.github.com/users/Arnavion/orgs","repos_url":"https://api.github.com/users/Arnavion/repos","events_url":"https://api.github.com/users/Arnavion/events{/privacy}","received_events_url":"https://api.github.com/users/Arnavion/received_events","type":"User","site_admin":false},"created_at":"2016-09-04T03:14:59Z","updated_at":"2016-09-04T03:14:59Z","body":">In fact, from reading this page I'm not sure how `createdCallback`, `attachedCallback`, etc. are supposed to be defined if the prototype of the current class isn't used following a super calls of things like `HTMLElement`.\r\n\r\nThe custom element spec specially makes the result of `new MyElement()` have a `MyElement` prototype. That's why there's an explicit \"register the function `MyElement` to produce `<my-element>` elements\" step so that `document.createElement(\"my-element\")` can return a `MyElement`.\r\n\r\nIn the general case of constructors returning new objects, the returned object does not have the prototype chain set to the constructor."}}
{"actor":{"display_login":"Arnavion"}}