Fixed false positive errors in empty optional binding patterns in declaration signatures (#50816)

This commit is contained in:
Mateusz Burzyński
2023-03-01 19:58:37 +01:00
committed by GitHub
parent 9c5b09cd21
commit 080f9c1c3f
4 changed files with 204 additions and 1 deletions

View File

@@ -25119,7 +25119,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function isInAmbientOrTypeNode(node: Node): boolean {
return !!(node.flags & NodeFlags.Ambient || findAncestor(node, n => isInterfaceDeclaration(n) || isTypeLiteralNode(n)));
return !!(node.flags & NodeFlags.Ambient || findAncestor(node, n => isInterfaceDeclaration(n) || isTypeAliasDeclaration(n) || isTypeLiteralNode(n)));
}
// Return the flow cache key for a "dotted name" (i.e. a sequence of identifiers
@@ -40653,6 +40653,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
// For a binding pattern, validate the initializer and exit
if (isBindingPattern(node.name)) {
if (isInAmbientOrTypeNode(node)) {
return;
}
const needCheckInitializer = hasOnlyExpressionInitializer(node) && node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement;
const needCheckWidenedType = !some(node.name.elements, not(isOmittedExpression));
if (needCheckInitializer || needCheckWidenedType) {