Skip to content

Commit 472afc4

Browse files
committed
add condition to bail at containing level
1 parent 6c29ddf commit 472afc4

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/compiler/checker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,6 +6386,8 @@ namespace ts {
63866386
// Only narrow when symbol is variable of type any or an object, union, or type parameter type
63876387
if (node && symbol.flags & SymbolFlags.Variable) {
63886388
if (isTypeAny(type) || type.flags & (TypeFlags.ObjectType | TypeFlags.Union | TypeFlags.TypeParameter)) {
6389+
const declaration = getDeclarationOfKind(symbol, SyntaxKind.VariableDeclaration);
6390+
const top = declaration && getDeclarationContainer(declaration);
63896391
const originalType = type;
63906392
const nodeStack: {node: Node, child: Node}[] = [];
63916393
loop: while (node.parent) {
@@ -6402,6 +6404,9 @@ namespace ts {
64026404
// Stop at the first containing file or module declaration
64036405
break loop;
64046406
}
6407+
if (node === top) {
6408+
break;
6409+
}
64056410
}
64066411

64076412
let nodes: {node: Node, child: Node};

0 commit comments

Comments
 (0)