Port TypeScript PR #60083: Don't issue implicit any when obtaining the implied type for a binding pattern #1120
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.
This PR ports TypeScript PR #60083 to prevent inappropriate implicit any errors when obtaining the implied type for binding patterns in destructuring scenarios.
Problem
Previously, binding patterns in destructuring parameter declarations would incorrectly trigger implicit any errors, even when the types could be properly inferred from context. For example:
Solution
The fix separates the core type widening logic from implicit any reporting by:
getWidenedLiteralTypeForInitializer
that contains only the type widening logic without implicit any reportingwidenTypeInferredFromInitializer
to delegate to the new functiongetTypeFromBindingElement
to callgetWidenedLiteralTypeForInitializer
directly when obtaining implied types for binding patternsChanges Made
getWidenedLiteralTypeForInitializer()
function ininternal/checker/checker.go
widenTypeInferredFromInitializer()
to use the new functiongetTypeFromBindingElement()
to call the new function for binding pattern type inferenceTesting
All existing tests pass, including the specific test cases from the original TypeScript issue:
destructuringParameterDeclaration9
(JavaScript with JSDoc types)destructuringParameterDeclaration10
(TypeScript with explicit types)The fix correctly removes the inappropriate implicit any errors while preserving proper type inference and other error reporting.
Fixes #1116.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.