{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11733","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11733/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11733/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11733/events","html_url":"https://github.com/Microsoft/TypeScript/issues/11733","id":183955583,"number":11733,"title":"Abstract classes compiler: Stop native implementation of an Abstract Class ","user":{"login":"Jordan-Hall","id":2092344,"avatar_url":"https://avatars.githubusercontent.com/u/2092344?v=3","gravatar_id":"","url":"https://api.github.com/users/Jordan-Hall","html_url":"https://github.com/Jordan-Hall","followers_url":"https://api.github.com/users/Jordan-Hall/followers","following_url":"https://api.github.com/users/Jordan-Hall/following{/other_user}","gists_url":"https://api.github.com/users/Jordan-Hall/gists{/gist_id}","starred_url":"https://api.github.com/users/Jordan-Hall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jordan-Hall/subscriptions","organizations_url":"https://api.github.com/users/Jordan-Hall/orgs","repos_url":"https://api.github.com/users/Jordan-Hall/repos","events_url":"https://api.github.com/users/Jordan-Hall/events{/privacy}","received_events_url":"https://api.github.com/users/Jordan-Hall/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-19T13:03:21Z","updated_at":"2016-10-19T15:02:14Z","closed_at":null,"body":"I'm willing to write the change to the compiler if people believe this is a good idea. Currently abstract classes are compiled into public classes in JavaScript. I know native Javascript doesn't support Abstract classes but you can make abstract classes not instantiate abstract classes.\r\n\r\n**Typescript Example:**\r\n```\r\nAbstract class AbstractService {\r\nconstructor(http:any){\r\n\t\tthis.http = http;\r\n\t}\r\n}\r\n```\r\n\r\n\r\n**Expected behavior:**\r\n\r\n````\r\n\"use strict\";\r\nclass AbstractService {\r\n    constructor(http) {\r\n        if (this.constructor.name === \"AbstractService\") {\r\n                throw new TypeError(\"Cannot construct an instances of a Abstract class\");\r\n         }\r\n        this.http = http;\r\n    }\r\n}\r\nexports.AbstractService = AbstractService;\r\n//# sourceMappingURL=AbstractService .abstract.js.map\r\n````\r\n\r\n**Actual behavior:** \r\n```\r\n\"use strict\";\r\nclass AbstractService {\r\n    constructor(http) {\r\n        this.http = http;\r\n    }\r\n}\r\nexports.AbstractService= AbstractService;\r\n//# sourceMappingURL=AbstractService.abstract.js.map\r\n```\r\n\r\nI'm currently use this to make abstract classes in native Javascript. It means we can now make open source projects in TypeScript and not have to worry about people extending from a Abstract class.  \r\n\r\nYou can also do the same with functions. this.functionName === Undefined.  You can even make sure the parameters are correct"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/254840159","html_url":"https://github.com/Microsoft/TypeScript/issues/11733#issuecomment-254840159","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11733","id":254840159,"user":{"login":"andy-ms","id":19274678,"avatar_url":"https://avatars.githubusercontent.com/u/19274678?v=3","gravatar_id":"","url":"https://api.github.com/users/andy-ms","html_url":"https://github.com/andy-ms","followers_url":"https://api.github.com/users/andy-ms/followers","following_url":"https://api.github.com/users/andy-ms/following{/other_user}","gists_url":"https://api.github.com/users/andy-ms/gists{/gist_id}","starred_url":"https://api.github.com/users/andy-ms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy-ms/subscriptions","organizations_url":"https://api.github.com/users/andy-ms/orgs","repos_url":"https://api.github.com/users/andy-ms/repos","events_url":"https://api.github.com/users/andy-ms/events{/privacy}","received_events_url":"https://api.github.com/users/andy-ms/received_events","type":"User","site_admin":false},"created_at":"2016-10-19T15:02:14Z","updated_at":"2016-10-19T15:02:14Z","body":"\"not have to worry about people extending from a Abstract class\" -- I presume you mean \"directly instantiating an abstract class\" instead?\r\nI don't see what that would accomplish, since JS users can still do this:\r\n\r\n```js\r\nnew (class extends AbstractService {})()\r\n```\r\n\r\nwhich doesn't technically *directly* instantiate it. You still can't force untyped users to implement all the methods you want an inheriting class to implement.\r\nBy the way, `if (new.target === AbstractService)` works in the latest version of node, but is not yet implemented in TypeScript (#2551)."}}
{"actor":{"display_login":"andy-ms"}}