-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
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 the catch
should be rare.
Because catch
is sugar over then(null, rejectFn)
, that form has the same issue.
Example 1: foo returns Promise<Hero>
foo(){
return Promise.resolve(new Hero('foo'));
}
Example 2: foo returns a Promise<{}> ! This is AWFUL
foo(){
return Promise.resolve(new Hero('foo'))
// Pick any of these to see the problem
.catch()
.catch(e => {})
.then(null, e => {})
}
Example 3: foo returns a Promise<{}> ! This is AWFUL TOO
foo(){
return Promise.resolve(new Hero('foo'))
// Pick either of these to see the problem
.catch(e => Promise.reject(e))
.then(null, e => Promise.reject(e))
}
Example 4: foo returns a Promise<Hero> ... but this is baroque
foo(){
return Promise.resolve(new Hero('foo'))
.then(_ => _, e => Promise.reject(e));
}
The problem is in the typings file I think. I contend that that catch
or then(null, rejectFn)
should be typed to return a Promise<Hero>.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue