Skip to content

Commit 86a543b

Browse files
committed
Restrict ignoring circular error to binding element contextual type checking
Signed-off-by: Babak K. Shandiz <[email protected]>
1 parent d00a5b7 commit 86a543b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11635,7 +11635,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1163511635
return getTypeOfFuncClassEnumModule(symbol);
1163611636
}
1163711637

11638-
if (checkMode !== CheckMode.Normal && checkMode) {
11638+
// When trying to get the *contextual* type of a binding element, it's possible to fall in a loop and therefore
11639+
// end up in a circularity-like situation. This is not a true circularity so we should not report such an error.
11640+
// For example, here the looping could happen when trying to get the type of `a` (binding element):
11641+
//
11642+
// const { a, b = a } = { a: 0 }
11643+
//
11644+
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
1163911645
return anyType;
1164011646
}
1164111647
return reportCircularityError(symbol);
@@ -11711,7 +11717,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1171111717
return getTypeOfFuncClassEnumModule(symbol);
1171211718
}
1171311719

11714-
if (checkMode !== CheckMode.Normal && checkMode) {
11720+
// When trying to get the *contextual* type of a binding element, it's possible to fall in a loop and therefore
11721+
// end up in a circularity-like situation. This is not a true circularity so we should not report such an error.
11722+
// For example, here the looping could happen when trying to get the type of `a` (binding element):
11723+
//
11724+
// const { a, b = a } = { a: 0 }
11725+
//
11726+
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
1171511727
return type;
1171611728
}
1171711729
return reportCircularityError(symbol);

0 commit comments

Comments
 (0)