{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/33638525","id":33638525,"diff_hunk":"@@ -4490,7 +4562,31 @@ namespace ts {\n                 return Ternary.False;\r\n             }\r\n \r\n-            function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): Ternary {\r\n+            function typeRelatedToEachType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {\r\n+                let result = Ternary.True;\r\n+                let targetTypes = target.types;\r\n+                for (let targetType of targetTypes) {\r\n+                    let related = isRelatedTo(source, targetType, reportErrors);\r\n+                    if (!related) {\r\n+                        return Ternary.False;\r\n+                    }\r\n+                    result &= related;\r\n+                }\r\n+                return result;\r\n+            }\r\n+\r\n+            function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {\r\n+                let sourceTypes = source.types;\r\n+                for (let i = 0, len = sourceTypes.length; i < len; i++) {\r","path":"src/compiler/checker.ts","position":619,"original_position":619,"commit_id":"fb1bf420b4ca1847330a0af894406c769322bf31","original_commit_id":"fb1bf420b4ca1847330a0af894406c769322bf31","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":"Use a for-of loop","created_at":"2015-07-01T00:16:18Z","updated_at":"2015-07-01T00:16:18Z","html_url":"https://github.com/Microsoft/TypeScript/pull/3622#discussion_r33638525","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/33638525"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3622#discussion_r33638525"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622","id":38503864,"html_url":"https://github.com/Microsoft/TypeScript/pull/3622","diff_url":"https://github.com/Microsoft/TypeScript/pull/3622.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/3622.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3622","number":3622,"state":"open","locked":false,"title":"Intersection types","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 implements intersection types, the logical complement of union types. A union type `A | B` represents an entity that has either type A or type B, whereas an intersection type `A & B` represents an entity that has both type A and type B.\r\n\r\n### Type Relationships\r\n\r\n* Identity: `A & A` is equivalent to `A`.\r\n* Commutativity: `A & B` is equivalent to `B & A` (except for call and construct signatures as noted below).\r\n* Associativity: `(A & B) & C` is equivalent to `A & (B & C)`.\r\n* Supertype collapsing: `A & B` is equivalent to `A` if `B` is a supertype of `A`.\r\n\r\n### Assignment compatibility\r\n\r\n* `A & B` is assignable to `X` if `A` is assignable to `X` or `B` is assignable to `X`.\r\n* `X` is assignable to `A & B` if `X` is assignable to `A` and `X` is assignable to `B`.\r\n\r\n### Properties and Index Signatures\r\n\r\nThe type `A & B` has a property `P` if `A` has a property `P` or `B` has a property `P`. If `A` has a property `P` of type `X` and `B` has a property `P` of type `Y`, then `A & B` has a property `P` of type `X & Y`.\r\n\r\nIndex signatures are similarly intersected.\r\n\r\n### Call and Construct Signatures\r\n\r\nIf `A` has a signature `F` and `B` has a signature `G`, then `A & B` has signatures `F` and `G` in that order (the order of signatures matter for purposes of overload resolution). Except for the order of signatures, the types `A & B` and `B & A` are equivalent.\r\n\r\n### Precedence\r\n\r\nSimilarly to expression operators, the `&` type operator has higher precedence than the `|` type operator. Thus `A & B | C & D` is parsed as `(A & B) | (C & D)`.\r\n\r\n### Primitive Types\r\n\r\nIt is possible to intersect primitive types (e.g. `string & number`), but it is not possible to actually create values of such types (other than `undefined`). Because such types can result from instantiation of generic types (which is performed lazily), it is not possible to consistently detect and error on the operations that create the types.\r\n\r\n### Examples\r\n\r\n```typescript\r\nfunction extend<T, U>(first: T, second: U): T & U {\r\n    let result = <T & U> {};\r\n    for (let id in first) {\r\n        result[id] = first[id];\r\n    }\r\n    for (let id in second) {\r\n        if (!result.hasOwnProperty(id)) {\r\n            result[id] = second[id];\r\n        }\r\n    }\r\n    return result;\r\n}\r\n\r\nvar x = extend({ a: \"hello\" }, { b: 42 });\r\nvar s = x.a;\r\nvar n = x.b;\r\n```\r\n\r\n```typescript\r\ntype LinkedList<T> = T & { next: LinkedList<T> };\r\n\r\ninterface Person {\r\n    name: string;\r\n}\r\n\r\nvar people: LinkedList<Person>;\r\nvar s = people.name;\r\nvar s = people.next.name;\r\nvar s = people.next.next.name;\r\nvar s = people.next.next.next.name;\r\n```\r\n\r\n```typescript\r\ninterface A { a: string }\r\ninterface B { b: string }\r\ninterface C { c: string }\r\n\r\nvar abc: A & B & C;\r\nabc.a = \"hello\";\r\nabc.b = \"hello\";\r\nabc.c = \"hello\";\r\n\r\ninterface X { x: A }\r\ninterface Y { x: B }\r\ninterface Z { x: C }\r\n\r\nvar xyz: X & Y & Z;\r\nxyz.x.a = \"hello\";\r\nxyz.x.b = \"hello\";\r\nxyz.x.c = \"hello\";\r\n\r\ntype F1 = (x: string) => string;\r\ntype F2 = (x: number) => number;\r\n\r\nvar f: F1 & F2;\r\nvar s = f(\"hello\");\r\nvar n = f(42);\r\n```\r\n\r\nFixes #1256.","created_at":"2015-06-25T01:14:38Z","updated_at":"2015-07-01T00:16:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f5a11c555eb62e76aea52a6bb99f9849a4106868","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3622/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/fb1bf420b4ca1847330a0af894406c769322bf31","head":{"label":"Microsoft:intersectionTypes","ref":"intersectionTypes","sha":"fb1bf420b4ca1847330a0af894406c769322bf31","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-30T22:59:48Z","pushed_at":"2015-07-01T00:11:37Z","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":870454,"stargazers_count":5734,"watchers_count":5734,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":614,"mirror_url":null,"open_issues_count":667,"forks":614,"open_issues":667,"watchers":5734,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"fe4612273ccc2017cfec598521eec5ce30bbd4dc","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-30T22:59:48Z","pushed_at":"2015-07-01T00:11:37Z","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":870454,"stargazers_count":5734,"watchers_count":5734,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":614,"mirror_url":null,"open_issues_count":667,"forks":614,"open_issues":667,"watchers":5734,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3622"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3622"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3622/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3622/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/fb1bf420b4ca1847330a0af894406c769322bf31"}}}}