{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/27993","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/27993/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/27993/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/27993/events","html_url":"https://github.com/Microsoft/TypeScript/issues/27993","id":372074975,"node_id":"MDU6SXNzdWUzNzIwNzQ5NzU=","number":27993,"title":"TypeScript doesn't narrow out `undefined` after constructor call when callee is `any`","user":{"login":"fatcerberus","id":4097841,"node_id":"MDQ6VXNlcjQwOTc4NDE=","avatar_url":"https://avatars2.githubusercontent.com/u/4097841?v=4","gravatar_id":"","url":"https://api.github.com/users/fatcerberus","html_url":"https://github.com/fatcerberus","followers_url":"https://api.github.com/users/fatcerberus/followers","following_url":"https://api.github.com/users/fatcerberus/following{/other_user}","gists_url":"https://api.github.com/users/fatcerberus/gists{/gist_id}","starred_url":"https://api.github.com/users/fatcerberus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatcerberus/subscriptions","organizations_url":"https://api.github.com/users/fatcerberus/orgs","repos_url":"https://api.github.com/users/fatcerberus/repos","events_url":"https://api.github.com/users/fatcerberus/events{/privacy}","received_events_url":"https://api.github.com/users/fatcerberus/received_events","type":"User","site_admin":false},"labels":[{"id":113970366,"node_id":"MDU6TGFiZWwxMTM5NzAzNjY=","url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21","default":false},{"id":1097658263,"node_id":"MDU6TGFiZWwxMDk3NjU4MjYz","url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Domain:%20Control%20Flow","name":"Domain: Control Flow","color":"1d76db","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-19T18:50:16Z","updated_at":"2018-10-20T00:36:04Z","closed_at":null,"author_association":"NONE","body":"TypeScript doesn't seem to narrow the type of a variable correctly in cases where the constructor being called is typed as `any`.  If the type of a variable includes `undefined` in its type signature, it's not narrowed out after a constructor call even though by definition (I think--correct me if I'm wrong) `new fn()` *must* always evaluate to an object if it doesn't throw first.\r\n\r\n**TypeScript Version:**  3.1.3\r\n\r\n<!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** constructor narrow\r\n\r\n**Code**\r\n\r\n```ts\r\nlet x: { [x: string]: any } | undefined;\r\nx = new (Object as any)();\r\n// AFAIK `x` can't possibly be undefined after this point\r\nconsole.log(x.foo);  // error: Object is possibly 'undefined'.\r\n```\r\n\r\n**Expected behavior:**\r\nNo error.\r\n\r\n**Actual behavior:**\r\nCompile-time error: `Object is possibly 'undefined'.`\r\n\r\n**Playground Link:**\r\nhttp://www.typescriptlang.org/play/#src=let%20x%3A%20%7B%20%5Bx%3A%20string%5D%3A%20any%20%7D%20%7C%20undefined%3B%0D%0Ax%20%3D%20new%20(Object%20as%20any)()%3B%0D%0Aconsole.log(x.foo)%3B%0D%0A"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/431533777","html_url":"https://github.com/Microsoft/TypeScript/issues/27993#issuecomment-431533777","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/27993","id":431533777,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTUzMzc3Nw==","user":{"login":"fatcerberus","id":4097841,"node_id":"MDQ6VXNlcjQwOTc4NDE=","avatar_url":"https://avatars2.githubusercontent.com/u/4097841?v=4","gravatar_id":"","url":"https://api.github.com/users/fatcerberus","html_url":"https://github.com/fatcerberus","followers_url":"https://api.github.com/users/fatcerberus/followers","following_url":"https://api.github.com/users/fatcerberus/following{/other_user}","gists_url":"https://api.github.com/users/fatcerberus/gists{/gist_id}","starred_url":"https://api.github.com/users/fatcerberus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatcerberus/subscriptions","organizations_url":"https://api.github.com/users/fatcerberus/orgs","repos_url":"https://api.github.com/users/fatcerberus/repos","events_url":"https://api.github.com/users/fatcerberus/events{/privacy}","received_events_url":"https://api.github.com/users/fatcerberus/received_events","type":"User","site_admin":false},"created_at":"2018-10-20T00:36:04Z","updated_at":"2018-10-20T00:36:04Z","author_association":"NONE","body":"Instead of a cast, would a non-null assertion be enough to squelch the error?\r\n\r\n```ts\r\nx = new (Object as any)()!;\r\nx.foo;\r\n```"}}
{"actor":{"display_login":"fatcerberus"}}