{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2010","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2010/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2010/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2010/events","html_url":"https://github.com/Microsoft/TypeScript/issues/2010","id":57338449,"number":2010,"title":"Promise-type checking gives false errors","user":{"login":"iislucas","id":415450,"avatar_url":"https://avatars.githubusercontent.com/u/415450?v=3","gravatar_id":"","url":"https://api.github.com/users/iislucas","html_url":"https://github.com/iislucas","followers_url":"https://api.github.com/users/iislucas/followers","following_url":"https://api.github.com/users/iislucas/following{/other_user}","gists_url":"https://api.github.com/users/iislucas/gists{/gist_id}","starred_url":"https://api.github.com/users/iislucas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iislucas/subscriptions","organizations_url":"https://api.github.com/users/iislucas/orgs","repos_url":"https://api.github.com/users/iislucas/repos","events_url":"https://api.github.com/users/iislucas/events{/privacy}","received_events_url":"https://api.github.com/users/iislucas/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20More%20Info","name":"Needs More Info","color":"556b75"}],"state":"open","locked":false,"assignee":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/8","html_url":"https://github.com/Microsoft/TypeScript/milestones/TypeScript%201.6","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/8/labels","id":900034,"number":8,"title":"TypeScript 1.6","description":"","creator":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"open_issues":85,"closed_issues":24,"state":"open","created_at":"2014-12-11T05:46:12Z","updated_at":"2015-05-06T18:10:36Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-02-11T16:22:07Z","updated_at":"2015-05-06T18:20:03Z","closed_at":null,"body":"The following code used to type-check fine (Using the types for Promises prior to: https://github.com/borisyankov/DefinitelyTyped/commit/c95561be3526f90f0e717734a659d1c01d0492d4 ), but since they now use types based on:  https://github.com/Microsoft/TypeScript/blob/master/src/lib/es6.d.ts#L3542 \r\nthe code produces false type errors. \r\n```ts\r\n/// <reference path='es6-promise.d.ts' />\r\n\r\ninterface T1 {\r\n  __t1: string;\r\n}\r\n\r\ninterface T2 {\r\n  __t2: string;\r\n}\r\n\r\ninterface T3 {\r\n  __t3: string;\r\n}\r\n\r\nfunction f1() : Promise<T1> {\r\n  return Promise.resolve({ __t1: \"foo_t1\" });\r\n}\r\n\r\nfunction f2(x:T1) : T2 {\r\n  return { __t2: x.__t1 + \":foo_21\" };\r\n}\r\n\r\nvar x3 = f1()\r\n  .then(f2, (e:Error) => {\r\n    console.log(\"error 1\");\r\n    throw e;\r\n  })\r\n  .then((x:T2) => {\r\n    return { __t3: x.__t2 + \"bar\" };\r\n  });\r\n```\r\nIt gives these errors (in TypeScript 1.4.1): \r\n```\r\npromise-oddity.ts(23,10):  error TS2453: \r\nThe type argument for type parameter 'U' cannot be inferred from the usage. \r\nConsider specifying the type arguments explicitly.\r\n  Type argument candidate 'T2' is not a valid type argument \r\nbecause it is not a supertype of candidate 'void'.\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/99559023","html_url":"https://github.com/Microsoft/TypeScript/issues/2010#issuecomment-99559023","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2010","id":99559023,"user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T18:20:03Z","updated_at":"2015-05-06T18:20:03Z","body":"The problem is that the error callback is void, and we try to make an inference from that void return type. You can tell because it works if you return something from your callback, like changing it to:\r\n```ts\r\n(e:Error) => {\r\n    console.log(\"error 1\");\r\n    throw e;\r\n    var t2: T2;\r\n    return t2;\r\n  }\r\n```\r\n\r\nI believe the correct fix is to add another overload to then (after the existing overload), that looks like this:\r\n```ts\r\nthen<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;\r\n```\r\nNote that this accounts for a void error function, but does not try to infer from it."}}