[Bug] Fix IPromise.finally() to await returned promises per ES2018 spec#508
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes IPromise.finally() (and the doFinally fallback when native .finally is unavailable) to comply with ES2018 §27.2.5.3: when the onFinally callback returns a thenable, the resulting promise now waits for that thenable to settle before propagating the original value/reason, and if the returned thenable rejects, that rejection replaces the original outcome.
Changes:
- Updated
_finallyinlib/src/promise/base.tsto await a thenable returned fromonFinallyin both fulfilled and rejected paths. - Updated the simulated-finally branch of
doFinallyinlib/src/promise/await.tsto do the same. - Broadened
FinallyPromiseHandlerto allow() => PromiseLike<void>and refreshed the related TypeDoc onIPromise.finally. - Refreshed transitive dependency versions in
common/config/rush/npm-shrinkwrap.json(notably@nevware21/ts-preproc0.1.4 → 0.1.5 with newerglobby/ignore).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/src/promise/base.ts | Await thenable returned by onFinally in both then/catch branches to comply with the spec. |
| lib/src/promise/await.ts | Mirror the same spec-compliant behavior in the doFinally simulated-finally fallback. |
| lib/src/interfaces/types.ts | Extend FinallyPromiseHandler to allow returning PromiseLike<void> and update the doc comment. |
| lib/src/interfaces/IPromise.ts | Update @param onfinally TypeDoc to describe the new async/awaiting semantics. |
| common/config/rush/npm-shrinkwrap.json | Lockfile refresh including @nevware21/ts-preproc 0.1.4→0.1.5 and related transitive bumps. |
Files not reviewed (1)
- common/config/rush/npm-shrinkwrap.json: Language not supported
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #508 +/- ##
==========================================
- Coverage 97.49% 96.96% -0.54%
==========================================
Files 27 27
Lines 1439 1450 +11
Branches 338 341 +3
==========================================
+ Hits 1403 1406 +3
- Misses 36 44 +8
🚀 New features to boost your workflow:
|
61c8655 to
8717f11
Compare
14193df to
94b3773
Compare
Promise.finally() was ignoring the return value of the onFinally callback. Per the ES2018 specification (ECMA-262 §27.2.5.3), if onFinally returns a promise/thenable, the resulting promise must wait for it to settle before propagating the original value or reason. If the returned promise rejects, that rejection must propagate. Fixed in: - lib/src/promise/base.ts (_finally implementation) - lib/src/promise/await.ts (doFinally fallback when .finally is unavailable) - lib/src/interfaces/types.ts (FinallyPromiseHandler type updated to allow PromiseLike<void>) - lib/src/interfaces/IPromise.ts (updated @param typedoc)
nev21
approved these changes
May 20, 2026
nev21
previously approved these changes
May 20, 2026
nev21
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Promise.finally() was ignoring the return value of the onFinally callback. Per the ES2018 specification (ECMA-262 §27.2.5.3), if onFinally returns a promise/thenable, the resulting promise must wait for it to settle before propagating the original value or reason. If the returned promise rejects, that rejection must propagate.
Fixed in: