Skip to content

Commit 2c4361a

Browse files
author
Andy
authored
Simplify assignTypeToParameterAndFixTypeParameters (microsoft#17706)
1 parent 8fde483 commit 2c4361a

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/compiler/checker.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16586,14 +16586,14 @@ namespace ts {
1658616586

1658716587
// When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
1658816588
// the destructured type into the contained binding elements.
16589-
function assignBindingElementTypes(node: VariableLikeDeclaration) {
16590-
if (isBindingPattern(node.name)) {
16591-
for (const element of node.name.elements) {
16592-
if (!isOmittedExpression(element)) {
16593-
if (element.name.kind === SyntaxKind.Identifier) {
16594-
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
16595-
}
16596-
assignBindingElementTypes(element);
16589+
function assignBindingElementTypes(pattern: BindingPattern) {
16590+
for (const element of pattern.elements) {
16591+
if (!isOmittedExpression(element)) {
16592+
if (element.name.kind === SyntaxKind.Identifier) {
16593+
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
16594+
}
16595+
else {
16596+
assignBindingElementTypes(element.name);
1659716597
}
1659816598
}
1659916599
}
@@ -16603,13 +16603,14 @@ namespace ts {
1660316603
const links = getSymbolLinks(parameter);
1660416604
if (!links.type) {
1660516605
links.type = contextualType;
16606-
const name = getNameOfDeclaration(parameter.valueDeclaration);
16607-
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
16608-
if (links.type === emptyObjectType &&
16609-
(name.kind === SyntaxKind.ObjectBindingPattern || name.kind === SyntaxKind.ArrayBindingPattern)) {
16610-
links.type = getTypeFromBindingPattern(<BindingPattern>name);
16606+
const decl = parameter.valueDeclaration as ParameterDeclaration;
16607+
if (decl.name.kind !== SyntaxKind.Identifier) {
16608+
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
16609+
if (links.type === emptyObjectType) {
16610+
links.type = getTypeFromBindingPattern(decl.name);
16611+
}
16612+
assignBindingElementTypes(decl.name);
1661116613
}
16612-
assignBindingElementTypes(<ParameterDeclaration>parameter.valueDeclaration);
1661316614
}
1661416615
}
1661516616

0 commit comments

Comments
 (0)