Fix incorrect rest element type inside contextually typed parameter (#47909)

* wip: possible fixes

* pass parameter type to assignBindingElementTypes

* undo unnecessary changes

* update baselines
This commit is contained in:
Gabriela Araujo Britto
2022-02-15 18:27:23 -03:00
committed by GitHub
parent d13af64bde
commit 67f47bf420
5 changed files with 138 additions and 4 deletions

View File

@@ -31851,21 +31851,22 @@ namespace ts {
if (links.type === unknownType) {
links.type = getTypeFromBindingPattern(declaration.name);
}
assignBindingElementTypes(declaration.name);
assignBindingElementTypes(declaration.name, links.type);
}
}
}
// When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
// the destructured type into the contained binding elements.
function assignBindingElementTypes(pattern: BindingPattern) {
function assignBindingElementTypes(pattern: BindingPattern, parentType: Type) {
for (const element of pattern.elements) {
if (!isOmittedExpression(element)) {
const type = getBindingElementTypeFromParentType(element, parentType);
if (element.name.kind === SyntaxKind.Identifier) {
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
getSymbolLinks(getSymbolOfNode(element)).type = type;
}
else {
assignBindingElementTypes(element.name);
assignBindingElementTypes(element.name, type);
}
}
}