Contextually type array literal spread operands - #64489
Open
Sahil Singh Kushwah (WhitefistEmperor) wants to merge 2 commits into
Open
Sahil Singh Kushwah (WhitefistEmperor) wants to merge 2 commits into
Sahil Singh Kushwah (WhitefistEmperor) wants to merge 2 commits into
Conversation
Copilot started reviewing on behalf of
Sahil Singh Kushwah (WhitefistEmperor)
September 28, 2026 06:40
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Multiple call spreads can receive parameter context from the wrong position, and two new expression paths lack regression coverage.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Propagates contextual types into array spread operands to preserve literal and tuple precision.
Changes:
- Adds spread-context derivation for arrays, tuples, and calls.
- Supports nested conditional/logical literal expressions.
- Adds regression tests and updates affected baselines.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Implements contextual spread typing. |
tsc/internal/checker/utilities.go |
Updates call-argument API usage. |
tsc/testdata/tests/cases/compiler/contextualTypingArraySpreadElements.ts |
Adds regression cases. |
tsc/testdata/baselines/reference/compiler/contextualTypingArraySpreadElements.types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/contextualTypingArraySpreadElements.symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/contextualTypingArraySpreadElements.js |
Records emitted JavaScript. |
tsc/testdata/baselines/reference/compiler/contextualTypingArraySpreadElements.errors.txt |
Records expected diagnostic. |
tsc/testdata/baselines/reference/compiler/literalFreshnessPropagationOnNarrowing.types |
Updates literal freshness types. |
tsc/testdata/baselines/reference/compiler/literalFreshnessPropagationOnNarrowing.errors.txt |
Removes resolved diagnostic. |
tsc/testdata/baselines/reference/compiler/awaitedType.types |
Updates Promise.all tuple precision. |
Author
|
@microsoft-github-policy-service agree |
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.


Fixes #45600
Summary
Array literals used as spread operands were checked without the contextual type of the containing array or call. This caused literal properties to widen prematurely—for example,
{ field: "a" }became{ field: string }—and produced an incorrect assignability error.This change propagates the relevant array or tuple context into spread operands.
Approach
||, and??expression trees containing array literals.This also improves tuple precision in an existing
Promise.allcase from[number, ...void[]]to[number, void]and resolves an existing literal-freshness case markedDesired: OK.Tests
Added regression coverage for:
The new regression produces no diagnostics for valid cases and exactly one
TS2322diagnostic for the intentional invalid control.Validation performed:
npx hereby validatecompleted all compiler, native-preview, lint, generation, and formatting stages successfully. The only local failures were the Windowsfswatchsymlink tests because the current account does not have permission to create symbolic links.AI assistance disclosure
I used OpenAI Codex to assist with investigating, implementing, and testing this change. I reviewed the resulting implementation and tests, understand the design and tradeoffs, and will personally respond to review feedback.