Skip to content

Commit abc9e68

Browse files
committed
Consolidate getting type parameter declarations
Create getEffectiveTypeParameterDeclarations in utilities.ts
1 parent eda7978 commit abc9e68

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6178,19 +6178,11 @@ namespace ts {
61786178
return undefined;
61796179
}
61806180

6181-
function getTypeParametersFromJSDocTemplate(declaration: DeclarationWithTypeParameters): TypeParameterDeclaration[] {
6182-
if (declaration.flags & NodeFlags.JavaScriptFile) {
6183-
const templateTag = getJSDocTemplateTag(declaration);
6184-
return templateTag && templateTag.typeParameters;
6185-
}
6186-
return undefined;
6187-
}
6188-
61896181
// Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual
61906182
// type checking functions).
61916183
function getTypeParametersFromDeclaration(declaration: DeclarationWithTypeParameters): TypeParameter[] {
61926184
let result: TypeParameter[];
6193-
forEach(declaration.typeParameters || getTypeParametersFromJSDocTemplate(declaration), node => {
6185+
forEach(getEffectiveTypeParameterDeclarations(declaration), node => {
61946186
const tp = getDeclaredTypeOfTypeParameter(node.symbol);
61956187
if (!contains(result, tp)) {
61966188
if (!result) {
@@ -8165,8 +8157,7 @@ namespace ts {
81658157
case SyntaxKind.ClassExpression:
81668158
case SyntaxKind.InterfaceDeclaration:
81678159
case SyntaxKind.TypeAliasDeclaration:
8168-
const declaration = node as DeclarationWithTypeParameters;
8169-
const typeParameters = declaration.typeParameters || getTypeParametersFromJSDocTemplate(declaration);
8160+
const typeParameters = getEffectiveTypeParameterDeclarations(node as DeclarationWithTypeParameters);
81708161
if (typeParameters) {
81718162
for (const d of typeParameters) {
81728163
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {

src/compiler/utilities.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,20 @@ namespace ts {
27432743
}
27442744
}
27452745

2746+
/**
2747+
* Gets the effective return type annotation of a signature. If the node was parsed in a
2748+
* JavaScript file, gets the return type annotation from JSDoc.
2749+
*/
2750+
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): TypeParameterDeclaration[] {
2751+
if (node.typeParameters) {
2752+
return node.typeParameters;
2753+
}
2754+
if (node.flags & NodeFlags.JavaScriptFile) {
2755+
const templateTag = getJSDocTemplateTag(node);
2756+
return templateTag && templateTag.typeParameters;
2757+
}
2758+
}
2759+
27462760
/**
27472761
* Gets the effective type annotation of the value parameter of a set accessor. If the node
27482762
* was parsed in a JavaScript file, gets the type annotation from JSDoc.

0 commit comments

Comments
 (0)