Repository navigation
fix(64954): exclude PromiseLike from contextual this in object literal methods - #64963
Open
Nate (servusdei2018) wants to merge 2 commits into
Open
Nate (servusdei2018) wants to merge 2 commits into
Nate (servusdei2018) wants to merge 2 commits into
Conversation
Nate (servusdei2018)
marked this pull request as ready for review
October 26, 2026 22:01
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The unconditional filter also removes legitimate thenable contextual types outside async returns, causing missing-property errors in previously valid code.
1 open issue
What changed in this PR
Addresses #64954 by excluding promise-like contextual types from this in object literal methods, targeting objects returned from async functions.
Changes:
- Filters promise-like contextual types, falling back to the literal’s own type when none remain.
- Adds an async-return regression test with type, symbol, and JavaScript baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/thisInObjectLiteralMethodAsyncReturn.ts |
Tests inferred and annotated async returns. |
tsc/testdata/baselines/reference/compiler/thisInObjectLiteralMethodAsyncReturn.types |
Records expected contextual this types. |
tsc/testdata/baselines/reference/compiler/thisInObjectLiteralMethodAsyncReturn.symbols |
Records expected symbol bindings. |
tsc/testdata/baselines/reference/compiler/thisInObjectLiteralMethodAsyncReturn.js |
Records emitted JavaScript. |
tsc/internal/checker/checker.go |
Filters promise-like types when determining contextual this. |
Review effort: Balanced
Comment on lines
+12293
to
+12295
| if contextualType != nil { | ||
| filtered := c.filterType(contextualType, func(t *Type) bool { | ||
| return c.getAwaitedTypeOfPromise(t) == nil |
This branch has not been deployed
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.

When an async arrow function has a contextual return type, the object literal it returns is contextually typed as
T | PromiseLike<T>. That union was then being used asthisinside the literal’s methods, which is wrong, sincethisis the literal itself. This change strips the promise-like members from the union before typingthis. If nothing is left after that, it falls back to the literal’s own type.Fixes #64954