From ee721225aeb3753a9522785f6ecf9d95a6f27346 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 4 Aug 2018 11:30:20 -0700 Subject: [PATCH] Ensure type parameters are erased in contextual signature from @type tag --- src/compiler/checker.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b2948d6bfce..850fcc940ec 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7565,10 +7565,15 @@ namespace ts { return true; } - function getReturnTypeOfTypeTag(node: SignatureDeclaration | JSDocSignature) { + function getSignatureOfTypeTag(node: SignatureDeclaration | JSDocSignature) { const typeTag = isInJavaScriptFile(node) ? getJSDocTypeTag(node) : undefined; const signature = typeTag && typeTag.typeExpression && getSingleCallSignature(getTypeFromTypeNode(typeTag.typeExpression)); - return signature && getReturnTypeOfSignature(getErasedSignature(signature)); + return signature && getErasedSignature(signature); + } + + function getReturnTypeOfTypeTag(node: SignatureDeclaration | JSDocSignature) { + const signature = getSignatureOfTypeTag(node); + return signature && getReturnTypeOfSignature(signature); } function containsArgumentsReference(declaration: SignatureDeclaration): boolean { @@ -16389,16 +16394,11 @@ namespace ts { // union type of return types from these signatures function getContextualSignature(node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature | undefined { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); - let type: Type | undefined; - if (isInJavaScriptFile(node)) { - const jsdoc = getJSDocType(node); - if (jsdoc) { - type = getTypeFromTypeNode(jsdoc); - } - } - if (!type) { - type = getContextualTypeForFunctionLikeDeclaration(node); + const typeTagSignature = getSignatureOfTypeTag(node); + if (typeTagSignature) { + return typeTagSignature; } + const type = getContextualTypeForFunctionLikeDeclaration(node); if (!type) { return undefined; }