Skip to content

Port TypeScript PR #60083: Don't issue implicit any when obtaining the implied type for a binding pattern #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15969,6 +15969,10 @@ func (c *Checker) padTupleType(t *Type, pattern *ast.Node) *Type {
}

func (c *Checker) widenTypeInferredFromInitializer(declaration *ast.Node, t *Type) *Type {
return c.getWidenedLiteralTypeForInitializer(declaration, t)
}

func (c *Checker) getWidenedLiteralTypeForInitializer(declaration *ast.Node, t *Type) *Type {
if c.getCombinedNodeFlagsCached(declaration)&ast.NodeFlagsConstant != 0 || isDeclarationReadonly(declaration) {
return t
}
Expand Down Expand Up @@ -17089,7 +17093,7 @@ func (c *Checker) getTypeFromBindingElement(element *ast.Node, includePatternInT
if ast.IsBindingPattern(element.Name()) {
contextualType = c.getTypeFromBindingPattern(element.Name(), true /*includePatternInType*/, false /*reportErrors*/)
}
return c.addOptionality(c.widenTypeInferredFromInitializer(element, c.checkDeclarationInitializer(element, CheckModeNormal, contextualType)))
return c.addOptionality(c.getWidenedLiteralTypeForInitializer(element, c.checkDeclarationInitializer(element, CheckModeNormal, contextualType)))
}
if ast.IsBindingPattern(element.Name()) {
return c.getTypeFromBindingPattern(element.Name(), includePatternInType, reportErrors)
Expand Down