Fixed ancestor lookup for more node types

This commit is contained in:
Mateusz Burzyński
2022-07-17 13:40:51 +02:00
parent 232a668ce0
commit 95ba58cced

View File

@@ -28086,15 +28086,20 @@ namespace ts {
// type with those properties for which the binding pattern specifies a default value.
// If the object literal is spread into another object literal, skip this step and let the top-level object
// literal handle it instead.
if (contextualTypeHasPattern && findAncestor(node, n => n === contextualType.pattern!.parent || (n.kind === SyntaxKind.SpreadAssignment && getContextualType(n.parent as Expression, /*contextFlags*/undefined)!.pattern === contextualType.pattern))!.kind !== SyntaxKind.SpreadAssignment) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
if (!(prop.flags & SymbolFlags.Optional)) {
error(prop.valueDeclaration || (prop as TransientSymbol).bindingElement,
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
if (contextualTypeHasPattern) {
const rootPatternParent = findAncestor(contextualType.pattern!.parent, n => n.kind === SyntaxKind.VariableDeclaration || n.kind === SyntaxKind.BinaryExpression || n.kind === SyntaxKind.Parameter);
const spreadOrOutsideRootObject = findAncestor(node, n => n === rootPatternParent || (n.kind === SyntaxKind.SpreadAssignment && getContextualType(n.parent as Expression, /*contextFlags*/ undefined)!.pattern === contextualType.pattern))!;
if (spreadOrOutsideRootObject.kind !== SyntaxKind.SpreadAssignment) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
if (!(prop.flags & SymbolFlags.Optional)) {
error(prop.valueDeclaration || (prop as TransientSymbol).bindingElement,
Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value);
}
propertiesTable.set(prop.escapedName, prop);
propertiesArray.push(prop);
}
propertiesTable.set(prop.escapedName, prop);
propertiesArray.push(prop);
}
}
}