Skip to content

Commit 22d46ac

Browse files
committed
Don't report circularities when parameter has itself as contextual type
1 parent 58e39ea commit 22d46ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5685,17 +5685,21 @@ namespace ts {
56855685
}
56865686

56875687
function reportCircularityError(symbol: Symbol) {
5688+
const declaration = <VariableLikeDeclaration>symbol.valueDeclaration;
56885689
// Check if variable has type annotation that circularly references the variable itself
5689-
if (getEffectiveTypeAnnotationNode(<VariableLikeDeclaration>symbol.valueDeclaration)) {
5690+
if (getEffectiveTypeAnnotationNode(declaration)) {
56905691
error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
56915692
symbolToString(symbol));
56925693
return errorType;
56935694
}
5694-
// Otherwise variable has initializer that circularly references the variable itself
5695-
if (noImplicitAny) {
5695+
// Check if variable has initializer that circularly references the variable itself
5696+
if (noImplicitAny && (<HasInitializer>declaration).initializer) {
56965697
error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
56975698
symbolToString(symbol));
56985699
}
5700+
// Circularities could also result from parameters in function expressions that end up
5701+
// having themselves as contextual types following type argument inference. In those cases
5702+
// we have already reported an implicit any error so we don't report anything here.
56995703
return anyType;
57005704
}
57015705

0 commit comments

Comments
 (0)