@@ -11832,9 +11832,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
11832
11832
function getTypeOfAlias(symbol: Symbol): Type {
11833
11833
const links = getSymbolLinks(symbol);
11834
11834
if (!links.type) {
11835
+ if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
11836
+ return errorType;
11837
+ }
11835
11838
const targetSymbol = resolveAlias(symbol);
11836
11839
const exportSymbol = symbol.declarations && getTargetOfAliasDeclaration(getDeclarationOfAliasSymbol(symbol)!, /*dontRecursivelyResolve*/ true);
11837
11840
const declaredType = firstDefined(exportSymbol?.declarations, d => isExportAssignment(d) ? tryGetTypeFromEffectiveTypeNode(d) : undefined);
11841
+
11838
11842
// It only makes sense to get the type of a value symbol. If the result of resolving
11839
11843
// the alias is not a value, then it has no type. To get the type associated with a
11840
11844
// type symbol, call getDeclaredTypeOfSymbol.
@@ -11845,6 +11849,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
11845
11849
: declaredType ? declaredType
11846
11850
: getSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
11847
11851
: errorType;
11852
+
11853
+ if (!popTypeResolution()) {
11854
+ reportCircularityError(exportSymbol ?? symbol);
11855
+ return links.type = errorType;
11856
+ }
11848
11857
}
11849
11858
return links.type;
11850
11859
}
@@ -11860,15 +11869,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
11860
11869
}
11861
11870
11862
11871
function reportCircularityError(symbol: Symbol) {
11863
- const declaration = symbol.valueDeclaration as VariableLikeDeclaration ;
11872
+ const declaration = symbol.valueDeclaration;
11864
11873
// Check if variable has type annotation that circularly references the variable itself
11865
- if (getEffectiveTypeAnnotationNode(declaration)) {
11866
- error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
11867
- return errorType;
11874
+ if (declaration) {
11875
+ if (getEffectiveTypeAnnotationNode(declaration)) {
11876
+ error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol));
11877
+ return errorType;
11878
+ }
11879
+ // Check if variable has initializer that circularly references the variable itself
11880
+ if (noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || (declaration as HasInitializer).initializer)) {
11881
+ 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, symbolToString(symbol));
11882
+ }
11868
11883
}
11869
- // Check if variable has initializer that circularly references the variable itself
11870
- if (noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || (declaration as HasInitializer).initializer)) {
11871
- 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, symbolToString(symbol));
11884
+ else if (symbol.flags & SymbolFlags.Alias) {
11885
+ const node = getDeclarationOfAliasSymbol(symbol);
11886
+ if (node) {
11887
+ error(node, Diagnostics.Circular_definition_of_import_alias_0, symbolToString(symbol));
11888
+ }
11872
11889
}
11873
11890
// Circularities could also result from parameters in function expressions that end up
11874
11891
// having themselves as contextual types following type argument inference. In those cases
0 commit comments