{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8554","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8554/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8554/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8554/events","html_url":"https://github.com/Microsoft/TypeScript/issues/8554","id":154271172,"number":8554,"title":"Generics inferred as {} versus void","user":{"login":"kitsonk","id":1282577,"avatar_url":"https://avatars.githubusercontent.com/u/1282577?v=3","gravatar_id":"","url":"https://api.github.com/users/kitsonk","html_url":"https://github.com/kitsonk","followers_url":"https://api.github.com/users/kitsonk/followers","following_url":"https://api.github.com/users/kitsonk/following{/other_user}","gists_url":"https://api.github.com/users/kitsonk/gists{/gist_id}","starred_url":"https://api.github.com/users/kitsonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitsonk/subscriptions","organizations_url":"https://api.github.com/users/kitsonk/orgs","repos_url":"https://api.github.com/users/kitsonk/repos","events_url":"https://api.github.com/users/kitsonk/events{/privacy}","received_events_url":"https://api.github.com/users/kitsonk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-11T15:23:09Z","updated_at":"2016-05-11T21:29:50Z","closed_at":null,"body":"**TypeScript Version:** \r\n\r\nany but using 1.9.0-dev.20160511\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction foo<T>(executor: (resolve: (value?: T) => void) => void): () => T {\r\n\treturn () => {\r\n\t\treturn <T> {};\r\n\t};\r\n};\r\n\r\nconst result1 = foo((resolve) => {\r\n\tresolve();\r\n});\r\n\r\nconst result2 = foo<void>((resolve) => {\r\n\tresolve();\r\n});\r\n\r\nresult1; // type is `() => {}`\r\nresult2; // type is `() => void`\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nWhen generics are contextually inferred with optional parameters, they result in a `void` type.\r\n\r\n**Actual behavior:** \r\n\r\nWhen generics are contextually inferred, they result in a `{}` type.\r\n\r\nThis in particular becomes a problem with `Promise` when:\r\n\r\n```typescript\r\nconst promise = new Promise((resolve) => {\r\n\tresolve();\r\n});\r\n\r\npromise; // type is Promise<{}>\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/218596079","html_url":"https://github.com/Microsoft/TypeScript/issues/8554#issuecomment-218596079","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8554","id":218596079,"user":{"login":"jeffreymorlan","id":1071296,"avatar_url":"https://avatars.githubusercontent.com/u/1071296?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffreymorlan","html_url":"https://github.com/jeffreymorlan","followers_url":"https://api.github.com/users/jeffreymorlan/followers","following_url":"https://api.github.com/users/jeffreymorlan/following{/other_user}","gists_url":"https://api.github.com/users/jeffreymorlan/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffreymorlan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffreymorlan/subscriptions","organizations_url":"https://api.github.com/users/jeffreymorlan/orgs","repos_url":"https://api.github.com/users/jeffreymorlan/repos","events_url":"https://api.github.com/users/jeffreymorlan/events{/privacy}","received_events_url":"https://api.github.com/users/jeffreymorlan/received_events","type":"User","site_admin":false},"created_at":"2016-05-11T21:29:50Z","updated_at":"2016-05-11T21:29:50Z","body":"That would require TypeScript to infer the type of the `resolve` argument from the way it's used inside the function, which is the opposite direction of usual type inference. Could get complicated."}}