{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/comments/69040371","id":69040371,"diff_hunk":"@@ -393,6 +410,111 @@ function createElement(tagName: string): Element {\n }\n ```\n \n+# Discriminated Unions\n+\n+You can combine string literal types, union types, type guards and type aliases to build an advanced pattern called *discriminated unions*.\n+Discriminated unions are useful in functional programming.\n+TypeScript doesn't have built-in support for this pattern, but you can get the compiler to check it once you have it set up.\n+There are four ingredients:\n+\n+1. Interfaces with a common property of a string-literal type\n+2. A type alias that unions the interfaces\n+3. Type guards on the common property\n+4. Exhaustiveness checking (optional)","path":"pages/Advanced Types.md","position":156,"original_position":156,"commit_id":"939650d392f389090b663bc5117234cfda5d4812","original_commit_id":"939650d392f389090b663bc5117234cfda5d4812","user":{"login":"sandersn","id":293473,"avatar_url":"https://avatars.githubusercontent.com/u/293473?v=3","gravatar_id":"","url":"https://api.github.com/users/sandersn","html_url":"https://github.com/sandersn","followers_url":"https://api.github.com/users/sandersn/followers","following_url":"https://api.github.com/users/sandersn/following{/other_user}","gists_url":"https://api.github.com/users/sandersn/gists{/gist_id}","starred_url":"https://api.github.com/users/sandersn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandersn/subscriptions","organizations_url":"https://api.github.com/users/sandersn/orgs","repos_url":"https://api.github.com/users/sandersn/repos","events_url":"https://api.github.com/users/sandersn/events{/privacy}","received_events_url":"https://api.github.com/users/sandersn/received_events","type":"User","site_admin":false},"body":"the whole table-of-contents or just (4)?","created_at":"2016-06-29T22:30:15Z","updated_at":"2016-06-29T22:30:15Z","html_url":"https://github.com/Microsoft/TypeScript-Handbook/pull/330#discussion_r69040371","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/comments/69040371"},"html":{"href":"https://github.com/Microsoft/TypeScript-Handbook/pull/330#discussion_r69040371"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330","id":75353434,"html_url":"https://github.com/Microsoft/TypeScript-Handbook/pull/330","diff_url":"https://github.com/Microsoft/TypeScript-Handbook/pull/330.diff","patch_url":"https://github.com/Microsoft/TypeScript-Handbook/pull/330.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/330","number":330,"state":"open","locked":false,"title":"Document discriminated unions","user":{"login":"sandersn","id":293473,"avatar_url":"https://avatars.githubusercontent.com/u/293473?v=3","gravatar_id":"","url":"https://api.github.com/users/sandersn","html_url":"https://github.com/sandersn","followers_url":"https://api.github.com/users/sandersn/followers","following_url":"https://api.github.com/users/sandersn/following{/other_user}","gists_url":"https://api.github.com/users/sandersn/gists{/gist_id}","starred_url":"https://api.github.com/users/sandersn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sandersn/subscriptions","organizations_url":"https://api.github.com/users/sandersn/orgs","repos_url":"https://api.github.com/users/sandersn/repos","events_url":"https://api.github.com/users/sandersn/events{/privacy}","received_events_url":"https://api.github.com/users/sandersn/received_events","type":"User","site_admin":false},"body":"Fixes #312\r\n\r\nAlso move intersection types together with union types.\r\nAlso some minor fixups.","created_at":"2016-06-27T17:59:33Z","updated_at":"2016-06-29T22:30:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5da2ee64bf5facda542add6e16e8da45a63763cd","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/330/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/statuses/939650d392f389090b663bc5117234cfda5d4812","head":{"label":"Microsoft:discriminated-unions","ref":"discriminated-unions","sha":"939650d392f389090b663bc5117234cfda5d4812","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":33742985,"name":"TypeScript-Handbook","full_name":"Microsoft/TypeScript-Handbook","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-Handbook","description":"The TypeScript Handbook is a comprehensive guide to the TypeScript language","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook","forks_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/deployments","created_at":"2015-04-10T18:03:58Z","updated_at":"2016-06-29T04:48:00Z","pushed_at":"2016-06-29T22:02:24Z","git_url":"git://github.com/Microsoft/TypeScript-Handbook.git","ssh_url":"git@github.com:Microsoft/TypeScript-Handbook.git","clone_url":"https://github.com/Microsoft/TypeScript-Handbook.git","svn_url":"https://github.com/Microsoft/TypeScript-Handbook","homepage":null,"size":1887,"stargazers_count":570,"watchers_count":570,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":239,"mirror_url":null,"open_issues_count":66,"forks":239,"open_issues":66,"watchers":570,"default_branch":"master"}},"base":{"label":"Microsoft:release-2.0","ref":"release-2.0","sha":"819891dd8762daadf6366ed9ec966c818a156006","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":33742985,"name":"TypeScript-Handbook","full_name":"Microsoft/TypeScript-Handbook","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-Handbook","description":"The TypeScript Handbook is a comprehensive guide to the TypeScript language","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook","forks_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/deployments","created_at":"2015-04-10T18:03:58Z","updated_at":"2016-06-29T04:48:00Z","pushed_at":"2016-06-29T22:02:24Z","git_url":"git://github.com/Microsoft/TypeScript-Handbook.git","ssh_url":"git@github.com:Microsoft/TypeScript-Handbook.git","clone_url":"https://github.com/Microsoft/TypeScript-Handbook.git","svn_url":"https://github.com/Microsoft/TypeScript-Handbook","homepage":null,"size":1887,"stargazers_count":570,"watchers_count":570,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":239,"mirror_url":null,"open_issues_count":66,"forks":239,"open_issues":66,"watchers":570,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330"},"html":{"href":"https://github.com/Microsoft/TypeScript-Handbook/pull/330"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/330"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/issues/330/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/pulls/330/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript-Handbook/statuses/939650d392f389090b663bc5117234cfda5d4812"}}}}
{"actor":{"display_login":"sandersn"}}