somePromise.catch or .then(null, rejectFn) should preserve type of original promise but doesn't #4903
Labels
Bug
A bug in TypeScript
Domain: lib.d.ts
The issue relates to the different libraries shipped with TypeScript
Fixed
A PR has been merged for this issue
Milestone
The fundamental point is that the
catch
of a promise should NOT change the type of that promise unless it returns something different. Returning something different is relatively rare because the activation of thecatch
should be rare.Because
catch
is sugar overthen(null, rejectFn)
, that form has the same issue.Example 1: foo returns Promise<Hero>
Example 2: foo returns a Promise<{}> ! This is AWFUL
Example 3: foo returns a Promise<{}> ! This is AWFUL TOO
Example 4: foo returns a Promise<Hero> ... but this is baroque
The problem is in the typings file I think. I contend that that
catch
orthen(null, rejectFn)
should be typed to return a Promise<Hero>.The text was updated successfully, but these errors were encountered: