Simplify assignTypeToParameterAndFixTypeParameters
(#17706)
This commit is contained in:
parent
8fde483393
commit
2c4361aadf
1 changed files with 15 additions and 14 deletions
|
@ -16586,14 +16586,14 @@ namespace ts {
|
|||
|
||||
// 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(node: VariableLikeDeclaration) {
|
||||
if (isBindingPattern(node.name)) {
|
||||
for (const element of node.name.elements) {
|
||||
if (!isOmittedExpression(element)) {
|
||||
if (element.name.kind === SyntaxKind.Identifier) {
|
||||
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
|
||||
}
|
||||
assignBindingElementTypes(element);
|
||||
function assignBindingElementTypes(pattern: BindingPattern) {
|
||||
for (const element of pattern.elements) {
|
||||
if (!isOmittedExpression(element)) {
|
||||
if (element.name.kind === SyntaxKind.Identifier) {
|
||||
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
|
||||
}
|
||||
else {
|
||||
assignBindingElementTypes(element.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16603,13 +16603,14 @@ namespace ts {
|
|||
const links = getSymbolLinks(parameter);
|
||||
if (!links.type) {
|
||||
links.type = contextualType;
|
||||
const name = getNameOfDeclaration(parameter.valueDeclaration);
|
||||
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
|
||||
if (links.type === emptyObjectType &&
|
||||
(name.kind === SyntaxKind.ObjectBindingPattern || name.kind === SyntaxKind.ArrayBindingPattern)) {
|
||||
links.type = getTypeFromBindingPattern(<BindingPattern>name);
|
||||
const decl = parameter.valueDeclaration as ParameterDeclaration;
|
||||
if (decl.name.kind !== SyntaxKind.Identifier) {
|
||||
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
|
||||
if (links.type === emptyObjectType) {
|
||||
links.type = getTypeFromBindingPattern(decl.name);
|
||||
}
|
||||
assignBindingElementTypes(decl.name);
|
||||
}
|
||||
assignBindingElementTypes(<ParameterDeclaration>parameter.valueDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue