{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/32600306","id":32600306,"diff_hunk":"@@ -10532,45 +10579,40 @@ namespace ts {\n             let symbol = getSymbolOfNode(node);\r\n             let type = <InterfaceType>getDeclaredTypeOfSymbol(symbol);\r\n             let staticType = <ObjectType>getTypeOfSymbol(symbol);\r\n+\r\n             let baseTypeNode = getClassExtendsHeritageClauseElement(node);\r\n             if (baseTypeNode) {\r\n-                if (!isSupportedExpressionWithTypeArguments(baseTypeNode)) {\r\n-                    error(baseTypeNode.expression, Diagnostics.Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses);\r\n-                }\r\n-\r\n                 emitExtends = emitExtends || !isInAmbientContext(node);\r\n-                checkExpressionWithTypeArguments(baseTypeNode);\r\n-            }\r\n-            let baseTypes = getBaseTypes(type);\r\n-            if (baseTypes.length) {\r\n-                if (produceDiagnostics) {\r\n+                let baseTypes = getBaseTypes(type);\r\n+                if (baseTypes.length && produceDiagnostics) {\r\n                     let baseType = baseTypes[0];\r\n+                    let staticBaseType = getBaseConstructorTypeOfClass(type);\r\n+                    if (baseTypeNode.typeArguments) {\r\n+                        let constructors = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);\r\n+                        checkTypeArgumentsAndConstraints(constructors[0].typeParameters, baseTypeNode.typeArguments);\r\n+                    }\r\n                     checkTypeAssignableTo(type, baseType, node.name || node, Diagnostics.Class_0_incorrectly_extends_base_class_1);\r\n-                    let staticBaseType = getTypeOfSymbol(baseType.symbol);\r\n-                    checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name || node,\r\n+                    checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,\r\n                         Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);\r\n-\r\n-                    if (baseType.symbol !== resolveEntityName(baseTypeNode.expression, SymbolFlags.Value)) {\r\n-                        error(baseTypeNode, Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType));\r\n+                    if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class)) {\r\n+                        // When the static base type is a \"class-like\" constructor function (but not actually a class), we verify\r\n+                        // that all instantiated base constructor signatures return the same type.\r\n+                        let constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);\r\n+                        if (forEach(constructors, sig => getReturnTypeOfSignature(sig) !== baseType)) {\r","path":"src/compiler/checker.ts","position":391,"original_position":391,"commit_id":"f6bcf7074caac8df6b4cd9b55269315cf2f03331","original_commit_id":"f6bcf7074caac8df6b4cd9b55269315cf2f03331","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"body":"I don't think types are usually compared by reference equality when checking a type system rule. Probably the correct thing here is to use isTypeIdenticalTo.","created_at":"2015-06-17T07:14:00Z","updated_at":"2015-06-17T07:14:00Z","html_url":"https://github.com/Microsoft/TypeScript/pull/3516#discussion_r32600306","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/32600306"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3516#discussion_r32600306"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516","id":37747227,"html_url":"https://github.com/Microsoft/TypeScript/pull/3516","diff_url":"https://github.com/Microsoft/TypeScript/pull/3516.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/3516.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3516","number":3516,"state":"open","locked":false,"title":"Allow expressions in class extends clauses","user":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"body":"This PR allows the `extends` clause of a class to specify an arbitrary expression that computes a constructor function. The PR also relaxes the strict requirement that `extends` specify a class type and instead allows expressions of \"class-like\" constructor function types. This means that built-in types can now be extended in class declarations.\r\n\r\nThe `extends` clause of a class previously required a type reference to be specified. It now accepts an expression optionally followed by a type argument list. The type of the expression must be a constructor function type with at least one construct signature that has the same number of type parameters as the number of type arguments specified in the `extends` clause. The return type of the matching construct signature(s) is the base type from which the class instance type inherits. Effectively, this allows both real classes and \"class-like\" expressions to be specified in the `extends` clause.\r\n\r\nSome examples:\r\n\r\n```typescript\r\n// Extend built-in types\r\n\r\nclass MyArray extends Array<number> { }\r\nclass MyError extends Error { }\r\n\r\n// Extend computed base class\r\n\r\nclass ThingA {\r\n    getGreeting() { return \"Hello from A\"; }\r\n}\r\n\r\nclass ThingB {\r\n    getGreeting() { return \"Hello from B\"; }\r\n}\r\n\r\ninterface Greeter {\r\n    getGreeting(): string;\r\n}\r\n\r\ninterface GreeterConstructor {\r\n    new (): Greeter;\r\n}\r\n\r\nfunction getGreeterBase(): GreeterConstructor {\r\n    return Math.random() >= 0.5 ? ThingA : ThingB;\r\n}\r\n\r\nclass Test extends getGreeterBase() {\r\n    sayHello() {\r\n        console.log(this.getGreeting());\r\n    }\r\n}\r\n```\r\n\r\nFixes #511.","created_at":"2015-06-15T23:46:47Z","updated_at":"2015-06-17T07:14:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1573c9dcf4d28043481ff00f32174dde7d2f0f5c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3516/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/f6bcf7074caac8df6b4cd9b55269315cf2f03331","head":{"label":"Microsoft:extendsExpressions","ref":"extendsExpressions","sha":"f6bcf7074caac8df6b4cd9b55269315cf2f03331","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-06-17T01:08:38Z","pushed_at":"2015-06-17T02:03:49Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":867833,"stargazers_count":5586,"watchers_count":5586,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":588,"mirror_url":null,"open_issues_count":653,"forks":588,"open_issues":653,"watchers":5586,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"718dc5b7a85b5cc37d91e991b640aa9aa556decd","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-06-17T01:08:38Z","pushed_at":"2015-06-17T02:03:49Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":867833,"stargazers_count":5586,"watchers_count":5586,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":588,"mirror_url":null,"open_issues_count":653,"forks":588,"open_issues":653,"watchers":5586,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3516"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3516"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3516/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3516/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/f6bcf7074caac8df6b4cd9b55269315cf2f03331"}}}}