{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/41697478","id":41697478,"diff_hunk":"@@ -10403,6 +10433,7 @@ namespace ts {\n                 case SyntaxKind.TemplateExpression:\r\n                     return checkTemplateExpression(<TemplateExpression>node);\r\n                 case SyntaxKind.StringLiteral:\r\n+                    return checkStringLiteralExpression(<LiteralExpression>node);\r\n                 case SyntaxKind.NoSubstitutionTemplateLiteral:\r","path":"src/compiler/checker.ts","position":174,"original_position":174,"commit_id":"ebc47d5e0213d31c7eee6111b7c9f09078c8f1ae","original_commit_id":"ebc47d5e0213d31c7eee6111b7c9f09078c8f1ae","user":{"login":"jbondc","id":199519,"avatar_url":"https://avatars.githubusercontent.com/u/199519?v=3","gravatar_id":"","url":"https://api.github.com/users/jbondc","html_url":"https://github.com/jbondc","followers_url":"https://api.github.com/users/jbondc/followers","following_url":"https://api.github.com/users/jbondc/following{/other_user}","gists_url":"https://api.github.com/users/jbondc/gists{/gist_id}","starred_url":"https://api.github.com/users/jbondc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbondc/subscriptions","organizations_url":"https://api.github.com/users/jbondc/orgs","repos_url":"https://api.github.com/users/jbondc/repos","events_url":"https://api.github.com/users/jbondc/events{/privacy}","received_events_url":"https://api.github.com/users/jbondc/received_events","type":"User","site_admin":false},"body":"So after peeking at Chrome, there doesn't seem to be anything specific for string inlining:\r\nhttps://github.com/v8/v8/blob/master/src/compiler/js-intrinsic-lowering.cc\r\n\r\nEven their implementation of a ```Set``` would appear to be slower then going straight to asm.js (but I could be wrong):\r\nhttps://github.com/v8/v8/blob/aca4a411e7082ffc790d79261ff383043de756ad/src/runtime/runtime-collections.cc\r\n","created_at":"2015-10-10T14:03:29Z","updated_at":"2015-10-10T14:03:29Z","html_url":"https://github.com/Microsoft/TypeScript/pull/5185#discussion_r41697478","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/41697478"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/5185#discussion_r41697478"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185","id":47210679,"html_url":"https://github.com/Microsoft/TypeScript/pull/5185","diff_url":"https://github.com/Microsoft/TypeScript/pull/5185.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/5185.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5185","number":5185,"state":"open","locked":false,"title":"String literal types","user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"body":"## String Literal Types\r\n\r\nThis pull request adds reasonable support for string literal types as proposed in #1003.\r\n\r\nA string literal type can be described by a string literal type node, which is otherwise the same lexically as the *StringLiteral* production in ECMAScript.\r\n\r\nA string literal type is a type whose expected value is a string with textual contents equal to that of the string literal type. In other words, there is no difference between `\"hello'world\"` and `'hello\\'world'`.\r\n\r\n```TypeScript\r\nlet tradition: \"hello world\" = 'hello world';\r\n\r\nlet quotes: \"hello'world\" = 'hello\\'world\";\r\n```\r\n\r\nString literal types can be used in conjunction with union types to describe a finite set of possible string values:\r\n\r\n```TypeScript\r\ntype CardinalDirection = \"North\"\r\n                       | \"East\"\r\n                       | \"South\"\r\n                       | \"West\";\r\n\r\nfunction move(distance: number, direction: CardinalDirection) {\r\n    // ...\r\n}\r\n```\r\n\r\nA string literal type can be considered a subtype of the `string` type. This means that a string literal type is assignable to a plain `string`, but not vice-versa.\r\n\r\nBecause of this distinction, string literals no longer always have the type `string`. Instead, a string literal's type is informed by its contextual type. The rules are the following:\r\n  * If a string literal is contextually typed by a string literal type with the same textual value, then it returns that string literal type.\r\n  * If a string literal is contextually typed by a union type containing a string literal type with the same textual value, then it returns that string literal type.\r\n\r\n```TypeScript\r\nlet a: \"foo\" | number = \"foo\"; // valid\r\nlet b: \"bar\" | \"baz\" = \"foo\";  // invalid\r\n```\r\n\r\nNote that intersections of string literals do not affect the type; `\"baz\"` will have the `string` type below, and the following assignment will fail:\r\n\r\n```TypeScript\r\nlet c: \"baz\" & { prop: number } = \"baz\"; // invalid\r\n```\r\n\r\nString literal types have the same apparent properties as `string` (i.e. the *String* global type), and are mostly compatible with operators like `+` in the same way that a `string` is:\r\n\r\n```TypeScript\r\nvar HELLO: \"HELLO\" = \"HELLO\";\r\nvar WORLD: \"WORLD\" = \"WORLD\";\r\nvar hello = HELLO.toLowerCase();  // type: string\r\nvar HELLOWORLD = HELLO + WORLD; // type: string\r\n```\r\n\r\nSpecialized signatures are also compatible with string literal types:\r\n\r\n```TypeScript\r\ninterface HTMLElement {\r\n    addEventListener(type: \"click\", listener: (ev: MouseEvent) => any, useCapture?: boolean): void;\r\n    addEventListener(type: \"focus\", listener: (ev: FocusEvent) => any, useCapture?: boolean): void;\r\n    addEventListener(type: \"drag\", listener: (ev: DragEvent) => any, useCapture?: boolean): void;\r\n}\r\n\r\nnamespace EventType {\r\n    export const Click: \"click\" = \"click\";\r\n    export const Focus: \"focus\" = \"focus\";\r\n    export const Drag: \"drag\" = \"drag\";\r\n}\r\n\r\nlet element: HTMLElement = /*...*/;\r\nelement.addEventListener(EventType.Click, ev => {\r\n    // 'ev' is correctly inferred to be a 'MouseEvent'\r\n    console.log(`x: '${ev.x}', y: '${ev.y}'`);\r\n}\r\n```\r\n\r\n---------\r\n\r\n## Open Questions\r\n\r\n* We could introduce a new form of type guards so that equality checks with string literals narrow `string`s to their respective string literals. Is this worthwhile?\r\n* Right now, signatures are only specialized if they have a parameter whose type is a string literal type. Should we expand this so that signatures are specialized if any of their parameters' types *contain* a string literal type within them?\r\n* Given that we have the textual content of a string literal type, we could reasonably perform property lookups in an object. I think this is worthwhile to consider. This would be even more useful if we performed narrowing.\r\n* Right now a string literal's type is only informed by a contextual type. Should `const` declarations imply that a string literal type should be used?\r\n* We currently allow `number` to be assignable to `enum`; however, this is due to how frequently people use flags in enums. Should we allow `string` to be assignable to a string literal type? I am personally against this idea.\r\n* Should the same typing rules for string literals apply to no-substitution template strings?","created_at":"2015-10-08T21:45:37Z","updated_at":"2015-10-10T14:03:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42ba71b0efb55d61ccbe4a2a1a6a45333bc78a56","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5185/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/ebc47d5e0213d31c7eee6111b7c9f09078c8f1ae","head":{"label":"Microsoft:stringLiteralTypes","ref":"stringLiteralTypes","sha":"ebc47d5e0213d31c7eee6111b7c9f09078c8f1ae","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-10-10T07:05:51Z","pushed_at":"2015-10-10T07:42:25Z","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":1110840,"stargazers_count":6967,"watchers_count":6967,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":785,"mirror_url":null,"open_issues_count":886,"forks":785,"open_issues":886,"watchers":6967,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"bff9148fe04a593688b17b34e5d7ed2313bf06d5","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-10-10T07:05:51Z","pushed_at":"2015-10-10T07:42:25Z","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":1110840,"stargazers_count":6967,"watchers_count":6967,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":785,"mirror_url":null,"open_issues_count":886,"forks":785,"open_issues":886,"watchers":6967,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/5185"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/5185"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/5185/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5185/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/ebc47d5e0213d31c7eee6111b7c9f09078c8f1ae"}}}}