diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1bbd710e32..9fcd0b593f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18017,7 +18017,7 @@ namespace ts { function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type { if (isInJavaScriptFile(node) && node.jsDoc) { - const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag)); + const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag && !!(tag as JSDocTypeTag).typeExpression && !!(tag as JSDocTypeTag).typeExpression.type)); if (typecasts && typecasts.length) { // We should have already issued an error if there were multiple type jsdocs const cast = typecasts[0] as JSDocTypeTag; diff --git a/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.js b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.js new file mode 100644 index 0000000000..06c7924440 --- /dev/null +++ b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.js @@ -0,0 +1,8 @@ +//// [index.js] +function Foo() {} +const a = /* @type string */(Foo); + + +//// [index.js] +function Foo() { } +var a = (Foo); diff --git a/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.symbols b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.symbols new file mode 100644 index 0000000000..7a9d98e39e --- /dev/null +++ b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/index.js === +function Foo() {} +>Foo : Symbol(Foo, Decl(index.js, 0, 0)) + +const a = /* @type string */(Foo); +>a : Symbol(a, Decl(index.js, 1, 5)) +>Foo : Symbol(Foo, Decl(index.js, 0, 0)) + diff --git a/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.types b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.types new file mode 100644 index 0000000000..590940b51f --- /dev/null +++ b/tests/baselines/reference/jsdocTypecastNoTypeNoCrash.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/index.js === +function Foo() {} +>Foo : () => void + +const a = /* @type string */(Foo); +>a : () => void +>(Foo) : () => void +>Foo : () => void + diff --git a/tests/cases/compiler/jsdocTypecastNoTypeNoCrash.ts b/tests/cases/compiler/jsdocTypecastNoTypeNoCrash.ts new file mode 100644 index 0000000000..8c5e52d34f --- /dev/null +++ b/tests/cases/compiler/jsdocTypecastNoTypeNoCrash.ts @@ -0,0 +1,5 @@ +// @allowJS: true +// @outDir: ./out +// @filename: index.js +function Foo() {} +const a = /* @type string */(Foo);