Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18052,7 +18052,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;
Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/jsdocTypecastNoTypeNoCrash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [index.js]
function Foo() {}
const a = /* @type string */(Foo);


//// [index.js]
function Foo() { }
var a = (Foo);
8 changes: 8 additions & 0 deletions tests/baselines/reference/jsdocTypecastNoTypeNoCrash.symbols
Original file line number Diff line number Diff line change
@@ -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))

9 changes: 9 additions & 0 deletions tests/baselines/reference/jsdocTypecastNoTypeNoCrash.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/index.js ===
function Foo() {}
>Foo : () => void

const a = /* @type string */(Foo);
>a : () => void
>(Foo) : () => void
>Foo : () => void

5 changes: 5 additions & 0 deletions tests/cases/compiler/jsdocTypecastNoTypeNoCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @allowJS: true
// @outDir: ./out
// @filename: index.js
function Foo() {}
const a = /* @type string */(Foo);