{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/16867","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/16867/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/16867/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/16867/events","html_url":"https://github.com/Microsoft/TypeScript/issues/16867","id":239846004,"number":16867,"title":"Type inference chooses incorrectly between overloads","user":{"login":"DylanRJohnston","id":5708800,"avatar_url":"https://avatars1.githubusercontent.com/u/5708800?v=3","gravatar_id":"","url":"https://api.github.com/users/DylanRJohnston","html_url":"https://github.com/DylanRJohnston","followers_url":"https://api.github.com/users/DylanRJohnston/followers","following_url":"https://api.github.com/users/DylanRJohnston/following{/other_user}","gists_url":"https://api.github.com/users/DylanRJohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/DylanRJohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DylanRJohnston/subscriptions","organizations_url":"https://api.github.com/users/DylanRJohnston/orgs","repos_url":"https://api.github.com/users/DylanRJohnston/repos","events_url":"https://api.github.com/users/DylanRJohnston/events{/privacy}","received_events_url":"https://api.github.com/users/DylanRJohnston/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-06-30T17:46:16Z","updated_at":"2017-06-30T17:55:13Z","closed_at":null,"body":"Example\r\n\r\n```\r\nimport * as SQS from 'aws-sdk/clients/sqs'\r\n\r\nconst _SQS = new SQS()\r\n\r\ntype Callback<E, R> = (e: E, r: R) => void\r\ntype NodeBack<A, E, R> = (a: A, c: Callback<E, R>) => any\r\n\r\nfunction promisify<A, E, R>(f: NodeBack<A, E, R>): (a: A) => Promise<R> {\r\n    return a => new Promise<R>((resolve, reject) => {\r\n        f(a, (e, r) => e ? reject(e) : resolve(r))\r\n    })\r\n}\r\n\r\n\r\nconst foo = promisify(_SQS.receiveMessage)\r\n```\r\n\r\nExpected type of foo\r\n```\r\n(a: SQS.ReceiveMessageRequest) => Promise<SQS.ReceiveMessageResult>\r\n```\r\n\r\nActual\r\n```\r\n(a: ((err: AWSError, data: SQS.ReceiveMessageResult) => void) | undefined) => Promise<{}>\r\n```\r\n\r\nThe AWS SDK has two overloads from the recieveMessage function\r\n\r\n```\r\nreceiveMessage(params: SQS.Types.ReceiveMessageRequest, callback?: (err: AWSError, data: SQS.Types.ReceiveMessageResult) => void): Request<SQS.Types.ReceiveMessageResult, AWSError>;\r\n\r\nreceiveMessage(callback?: (err: AWSError, data: SQS.Types.ReceiveMessageResult) => void): Request<SQS.Types.ReceiveMessageResult, AWSError>;\r\n  /**\r\n```\r\n\r\nSo when the generic types are being resolved, Typescript chooses the second overload assigning A to the callback type and assigning {} to E and R. Instead of using the overload that actually matches the `NodeBack<A, E, R>` type signature.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/312333012","html_url":"https://github.com/Microsoft/TypeScript/issues/16867#issuecomment-312333012","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/16867","id":312333012,"user":{"login":"DylanRJohnston","id":5708800,"avatar_url":"https://avatars1.githubusercontent.com/u/5708800?v=3","gravatar_id":"","url":"https://api.github.com/users/DylanRJohnston","html_url":"https://github.com/DylanRJohnston","followers_url":"https://api.github.com/users/DylanRJohnston/followers","following_url":"https://api.github.com/users/DylanRJohnston/following{/other_user}","gists_url":"https://api.github.com/users/DylanRJohnston/gists{/gist_id}","starred_url":"https://api.github.com/users/DylanRJohnston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DylanRJohnston/subscriptions","organizations_url":"https://api.github.com/users/DylanRJohnston/orgs","repos_url":"https://api.github.com/users/DylanRJohnston/repos","events_url":"https://api.github.com/users/DylanRJohnston/events{/privacy}","received_events_url":"https://api.github.com/users/DylanRJohnston/received_events","type":"User","site_admin":false},"created_at":"2017-06-30T17:55:12Z","updated_at":"2017-06-30T17:55:12Z","body":"Declaring the overloads for `Foo.method` in the opposite order gives the desired inference, but this seems to run counter to the logic of how overloads are chosen."}}
{"actor":{"display_login":"DylanRJohnston"}}