@@ -5252,6 +5252,10 @@ namespace ts {
5252
5252
}
5253
5253
5254
5254
function getDeclaredTypeOfSymbol(symbol: Symbol): Type {
5255
+ return tryGetDeclaredTypeOfSymbol(symbol) || unknownType;
5256
+ }
5257
+
5258
+ function tryGetDeclaredTypeOfSymbol(symbol: Symbol): Type | undefined {
5255
5259
if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
5256
5260
return getDeclaredTypeOfClassOrInterface(symbol);
5257
5261
}
@@ -5270,7 +5274,7 @@ namespace ts {
5270
5274
if (symbol.flags & SymbolFlags.Alias) {
5271
5275
return getDeclaredTypeOfAlias(symbol);
5272
5276
}
5273
- return unknownType ;
5277
+ return undefined ;
5274
5278
}
5275
5279
5276
5280
// A type reference is considered independent if each type argument is considered independent.
@@ -6872,17 +6876,6 @@ namespace ts {
6872
6876
return type;
6873
6877
}
6874
6878
6875
- /**
6876
- * Get type from reference to named type that cannot be generic (enum or type parameter)
6877
- */
6878
- function getTypeFromNonGenericTypeReference(node: TypeReferenceType, symbol: Symbol): Type {
6879
- if (node.typeArguments) {
6880
- error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
6881
- return unknownType;
6882
- }
6883
- return getDeclaredTypeOfSymbol(symbol);
6884
- }
6885
-
6886
6879
function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined {
6887
6880
switch (node.kind) {
6888
6881
case SyntaxKind.TypeReference:
@@ -6919,24 +6912,34 @@ namespace ts {
6919
6912
return type;
6920
6913
}
6921
6914
6922
- if (symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node)) {
6923
- // A jsdoc TypeReference may have resolved to a value (as opposed to a type). If
6924
- // the symbol is a constructor function, return the inferred class type; otherwise,
6925
- // the type of this reference is just the type of the value we resolved to.
6926
- const valueType = getTypeOfSymbol(symbol);
6927
- if (valueType.symbol && !isInferredClassType(valueType)) {
6928
- const referenceType = getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
6929
- if (referenceType) {
6930
- return referenceType;
6931
- }
6915
+ // Get type from reference to named type that cannot be generic (enum or type parameter)
6916
+ const res = tryGetDeclaredTypeOfSymbol(symbol);
6917
+ if (res !== undefined) {
6918
+ if (typeArguments) {
6919
+ error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
6920
+ return unknownType;
6932
6921
}
6922
+ return res;
6923
+ }
6933
6924
6934
- // Resolve the type reference as a Type for the purpose of reporting errors.
6935
- resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type);
6936
- return valueType;
6925
+ if (!(symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node))) {
6926
+ return unknownType;
6927
+ }
6928
+
6929
+ // A jsdoc TypeReference may have resolved to a value (as opposed to a type). If
6930
+ // the symbol is a constructor function, return the inferred class type; otherwise,
6931
+ // the type of this reference is just the type of the value we resolved to.
6932
+ const valueType = getTypeOfSymbol(symbol);
6933
+ if (valueType.symbol && !isInferredClassType(valueType)) {
6934
+ const referenceType = getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
6935
+ if (referenceType) {
6936
+ return referenceType;
6937
+ }
6937
6938
}
6938
6939
6939
- return getTypeFromNonGenericTypeReference(node, symbol);
6940
+ // Resolve the type reference as a Type for the purpose of reporting errors.
6941
+ resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type);
6942
+ return valueType;
6940
6943
}
6941
6944
6942
6945
function getTypeReferenceTypeWorker(node: TypeReferenceType, symbol: Symbol, typeArguments: Type[]): Type | undefined {
0 commit comments