{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17370","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17370/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17370/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17370/events","html_url":"https://github.com/Microsoft/TypeScript/issues/17370","id":245054185,"number":17370,"title":"Non-null assertion operator and the typeof operator","user":{"login":"bradzacher","id":7462525,"avatar_url":"https://avatars1.githubusercontent.com/u/7462525?v=4","gravatar_id":"","url":"https://api.github.com/users/bradzacher","html_url":"https://github.com/bradzacher","followers_url":"https://api.github.com/users/bradzacher/followers","following_url":"https://api.github.com/users/bradzacher/following{/other_user}","gists_url":"https://api.github.com/users/bradzacher/gists{/gist_id}","starred_url":"https://api.github.com/users/bradzacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradzacher/subscriptions","organizations_url":"https://api.github.com/users/bradzacher/orgs","repos_url":"https://api.github.com/users/bradzacher/repos","events_url":"https://api.github.com/users/bradzacher/events{/privacy}","received_events_url":"https://api.github.com/users/bradzacher/received_events","type":"User","site_admin":false},"labels":[{"id":117630560,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/In%20Discussion","name":"In Discussion","color":"556b75","default":false},{"id":113971155,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2017-07-24T11:45:19Z","updated_at":"2017-07-25T18:12:08Z","closed_at":null,"body":"**TypeScript Version:**  2.4.1\r\n\r\n**Code**\r\n\r\n```ts\r\n// strictNullChecks: true\r\n\r\nlet x : string | undefined\r\nlet y = x!\r\n\r\ntype t1 = typeof x!\r\ntype t2 = typeof y\r\n```\r\n\r\n**Expected behavior:**\r\nthe `t1` statement should create a `type` of type `string`.\r\nthe `t2` statement should create a `type` of type `string`.\r\n\r\n**Actual behavior:**\r\nthe `t1` statement errors with `';' semicolon expected`.\r\nthe `t2` statement creates a `type` of type `string`.\r\n\r\nThere appears to be no way to achieve this without defining a separate variable, or by type guarding  to remove the `undefined` / `null`.\r\n\r\nWith strict null checks on, this is especially troublesome in the case of generics with extends clauses, i.e.\r\n\r\n```TS\r\nclass Foo {}\r\nclass Bar<T extends Foo> {}\r\n\r\nconst x : Foo | undefined\r\n\r\nconst y = new Bar<typeof x>() // throws an exception because typeof x === Foo | undefined != Foo\r\n```\r\n\r\nIt would be great if the non-null assertion operator worked natively in typeof statements, or even if you could use brackets to resolve the assertion before the typeof."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/317822539","html_url":"https://github.com/Microsoft/TypeScript/issues/17370#issuecomment-317822539","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17370","id":317822539,"user":{"login":"Igorbek","id":1929486,"avatar_url":"https://avatars2.githubusercontent.com/u/1929486?v=4","gravatar_id":"","url":"https://api.github.com/users/Igorbek","html_url":"https://github.com/Igorbek","followers_url":"https://api.github.com/users/Igorbek/followers","following_url":"https://api.github.com/users/Igorbek/following{/other_user}","gists_url":"https://api.github.com/users/Igorbek/gists{/gist_id}","starred_url":"https://api.github.com/users/Igorbek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Igorbek/subscriptions","organizations_url":"https://api.github.com/users/Igorbek/orgs","repos_url":"https://api.github.com/users/Igorbek/repos","events_url":"https://api.github.com/users/Igorbek/events{/privacy}","received_events_url":"https://api.github.com/users/Igorbek/received_events","type":"User","site_admin":false},"created_at":"2017-07-25T18:12:08Z","updated_at":"2017-07-25T18:12:08Z","body":"@RyanCavanaugh is #6606 accepting PRs even in expression-based syntax?"}}
{"actor":{"display_login":"Igorbek"}}