Skip to content

fix Promise.finally() to return new promise via .then()#1696

Merged
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
RealColdFry:fix/promise-finally-returns-self
Mar 28, 2026
Merged

fix Promise.finally() to return new promise via .then()#1696
Perryvw merged 3 commits intoTypeScriptToLua:masterfrom
RealColdFry:fix/promise-finally-returns-self

Conversation

@RealColdFry
Copy link
Copy Markdown
Contributor

Fixes #1660

Promise.finally() was using a finallyCallbacks array and returning this, which breaks reference identity (p1.finally() === p1 was true) and doesn't match the ES spec.

Rewrites finally() to delegate to .then(), which:

  • Returns a new promise
  • Preserves the original fulfillment value / rejection reason
  • Removes the now-unused finallyCallbacks field and its handling in invokeCallbacks

Added tests for identity, value preservation, and rejection passthrough.

Remove redundant tests that relied on synchronous polyfill behavior
differing from JS. Keep only the identity check which matches JS.
@RealColdFry RealColdFry marked this pull request as ready for review March 27, 2026 10:33
@Perryvw Perryvw merged commit 8c856f1 into TypeScriptToLua:master Mar 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promise.prototype.finally() should return a new Promise

2 participants