Repository navigation
fix(65069): preserve contextual types for array-destructured parameter defaults - #65070
Open
Timur Vural (timurzvural) wants to merge 1 commit into
Open
Timur Vural (timurzvural) wants to merge 1 commit into
Timur Vural (timurzvural) wants to merge 1 commit into
Conversation
…r defaults Skip padTupleType when the parameter already has a contextual type, matching the object-pattern guard for microsoft#64974. Also apply the same guard to padObjectLiteralType so object `= {}` defaults keep working on the same path. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change preserving contextual types in destructured parameter defaults has no active review issues.
No open issues 🎉
What changed in this PR
Fixes #65069 by preserving contextual types for array-destructured parameter defaults in the native TypeScript checker. The same guard also addresses object defaults from #64974.
Changes:
- Skip tuple and object padding when the parameter has a contextual type.
- Add regression cases for object defaults, array defaults, callbacks, and nested/rest destructuring.
- Update type, symbol, and diagnostic baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/objectBindingPatternDefaultMissingElements.ts |
Adds contextual-typing regression cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.types |
Records preserved binding-element types. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.symbols |
Records symbols for the added cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.errors.txt |
Records expected assignment errors that verify contextual typing. |
tsc/internal/checker/checker.go |
Guards object and tuple padding with a contextual-type check. |
Review effort: Balanced
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 #65069.
Bug
In 7.1, a destructured parameter with a default like
= []loses its contextual type and reportsTS7031on binding elements. The object form (= {}) is #64974; this PR covers the array form and also guards object padding the same way.Fix
In
checkDeclarationInitializer, only callpadTupleType/padObjectLiteralTypewhengetContextualTypeForVariableLikeDeclaration(root, ContextFlagsNone) == nil. Padding inventsany-typed missing elements and must not override a contextual parameter type.Tests
Extended
objectBindingPatternDefaultMissingElements.ts(and baselines) with array/= []cases from #65069 and an object/= {}case.Related
= []default loses its contextual type (TS7031) #65069= {}default loses its contextual type (TS7031) #64974 (open fix(64974): fix contextual typing for destructured parameter defaults #64978 only guards objects today)AI assistance disclosure
This PR was authored with assistance from Cursor Agent. I have read and understand the change and am prepared to discuss and revise it in review.