{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/14161","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/14161/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/14161/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/14161/events","html_url":"https://github.com/Microsoft/TypeScript/pull/14161","id":208592373,"number":14161,"title":"Literal assertions","user":{"login":"gcnew","id":4066840,"avatar_url":"https://avatars1.githubusercontent.com/u/4066840?v=4","gravatar_id":"","url":"https://api.github.com/users/gcnew","html_url":"https://github.com/gcnew","followers_url":"https://api.github.com/users/gcnew/followers","following_url":"https://api.github.com/users/gcnew/following{/other_user}","gists_url":"https://api.github.com/users/gcnew/gists{/gist_id}","starred_url":"https://api.github.com/users/gcnew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gcnew/subscriptions","organizations_url":"https://api.github.com/users/gcnew/orgs","repos_url":"https://api.github.com/users/gcnew/repos","events_url":"https://api.github.com/users/gcnew/events{/privacy}","received_events_url":"https://api.github.com/users/gcnew/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-02-18T00:26:42Z","updated_at":"2018-03-09T10:35:24Z","closed_at":"2017-05-22T23:45:13Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/14161","html_url":"https://github.com/Microsoft/TypeScript/pull/14161","diff_url":"https://github.com/Microsoft/TypeScript/pull/14161.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/14161.patch"},"body":"<!--\r\nThank you for submitting a pull request!\r\n\r\nHere's a checklist you might find useful.\r\n[ ] There is an associated issue that is labelled\r\n  'Bug' or 'Accepting PRs' or is in the Community milestone\r\n[ ] Code is up-to-date with the `master` branch\r\n[ ] You've successfully run `jake runtests` locally\r\n[ ] You've signed the CLA\r\n[ ] There are new or updated unit tests validating the change\r\n\r\nRefer to CONTRIBUTING.MD for more details.\r\n  https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\nFixes #14156 \r\n\r\nDisallow unrelated literal type assertions. E.g.\r\n\r\n```ts\r\n0 as 0; // OK\r\n0 as 1; // Error\r\n\r\nfalse as (false | string); // OK\r\nfalse as (true | string);  // Error\r\nfalse as (boolean | string);  // OK\r\n\r\n'hello' as 'str'; // Error\r\n'hello' as 'hello'; // OK\r\n'hello' as ('str' | 123); // Error\r\n'hello' as ('hello' | 123); // OK\r\n'hello' as ('str' & 'hello'); // OK\r\n'hello' as ('str' | 'hello'); // OK\r\n'hello' as (1 | 2 | string); // OK\r\n'hello' as ('str' & { _brand: any }); // Error\r\n'hello' as ('hello' & { _brand: any }); // OK\r\n'hello' as ('str' & { _brand: any } | 1); // Error\r\n'hello' as ('hello' & { _brand: any } | 1); // OK\r\n\r\n('string' as string as 'literal'); // OK\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/371776423","html_url":"https://github.com/Microsoft/TypeScript/pull/14161#issuecomment-371776423","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/14161","id":371776423,"user":{"login":"laughinghan","id":225809,"avatar_url":"https://avatars2.githubusercontent.com/u/225809?v=4","gravatar_id":"","url":"https://api.github.com/users/laughinghan","html_url":"https://github.com/laughinghan","followers_url":"https://api.github.com/users/laughinghan/followers","following_url":"https://api.github.com/users/laughinghan/following{/other_user}","gists_url":"https://api.github.com/users/laughinghan/gists{/gist_id}","starred_url":"https://api.github.com/users/laughinghan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laughinghan/subscriptions","organizations_url":"https://api.github.com/users/laughinghan/orgs","repos_url":"https://api.github.com/users/laughinghan/repos","events_url":"https://api.github.com/users/laughinghan/events{/privacy}","received_events_url":"https://api.github.com/users/laughinghan/received_events","type":"User","site_admin":false},"created_at":"2018-03-09T10:35:24Z","updated_at":"2018-03-09T10:35:24Z","author_association":"NONE","body":"https://github.com/Microsoft/TypeScript/issues/14156#issuecomment-299965629 makes sense, but only applies to expressions where there's potentially something the compiler doesn't know. #22038 could be ameliorated with a rule like this that only applies to actual syntactic literals, not just expressions that evaluate to a literal type."}}
{"actor":{"display_login":"laughinghan"}}