stefanpenner / es6-promise

A polyfill for ES6-style Promises
MIT License
7.3k stars 593 forks source link

Fixed type definition for `Promise.finally` #348

Closed Lucretiel closed 5 years ago

Lucretiel commented 5 years ago

Per the docs:

A finally callback will not receive any argument, since there's no reliable means of determining if the promise was fulfilled or rejected. This use case is for precisely when you do not care about the rejection reason, or the fulfillment value, and so there's no need to provide it.

Unlike Promise.resolve(2).then(() => {}, () => {}) (which will be resolved with undefined), Promise.resolve(2).finally(() => {}) will be resolved with 2.

A throw (or returning a rejected promise) in the finally callback will reject the new promise with the rejection reason specified when calling throw().

Lucretiel commented 5 years ago

Note: A more appropriate return type would be onFullfilled?: () => (void | Thenable<void>), but that's technically stricter than what the docs allow.

stefanpenner commented 5 years ago

thanks, LGTM