Fix getEffectiveTypeAnnotationNode

Prevent it from using the (return) type of a function.  Could also check
the condition before calling the function, but there are two places that
need the check, and OTOH, all calls check the result so returning
`undefined` should work.

(This problem was introduced in PR#32553.)

Fixes #33741.
This commit is contained in:
Eli Barzilay
2020-01-03 15:30:41 -05:00
parent 5cc58deb57
commit d6c05a1358
5 changed files with 169 additions and 1 deletions

View File

@@ -3865,9 +3865,11 @@ namespace ts {
/**
* Gets the effective type annotation of a variable, parameter, or property. If the node was
* parsed in a JavaScript file, gets the type annotation from JSDoc.
* parsed in a JavaScript file, gets the type annotation from JSDoc. Also gets the type of
* functions only the JSDoc case.
*/
export function getEffectiveTypeAnnotationNode(node: Node): TypeNode | undefined {
if (!isInJSFile(node) && isFunctionDeclaration(node)) return undefined;
const type = (node as HasType).type;
if (type || !isInJSFile(node)) return type;
return isJSDocPropertyLikeTag(node) ? node.typeExpression && node.typeExpression.type : getJSDocType(node);