Skip to content

Commit 73eff81

Browse files
authored
Fix 18224 (#18259)
* Probably fix 18224 * Corrected test
1 parent 36607e1 commit 73eff81

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18017,7 +18017,7 @@ namespace ts {
1801718017

1801818018
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
1801918019
if (isInJavaScriptFile(node) && node.jsDoc) {
18020-
const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag));
18020+
const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag && !!(tag as JSDocTypeTag).typeExpression && !!(tag as JSDocTypeTag).typeExpression.type));
1802118021
if (typecasts && typecasts.length) {
1802218022
// We should have already issued an error if there were multiple type jsdocs
1802318023
const cast = typecasts[0] as JSDocTypeTag;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [index.js]
2+
function Foo() {}
3+
const a = /* @type string */(Foo);
4+
5+
6+
//// [index.js]
7+
function Foo() { }
8+
var a = (Foo);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/index.js ===
2+
function Foo() {}
3+
>Foo : Symbol(Foo, Decl(index.js, 0, 0))
4+
5+
const a = /* @type string */(Foo);
6+
>a : Symbol(a, Decl(index.js, 1, 5))
7+
>Foo : Symbol(Foo, Decl(index.js, 0, 0))
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/index.js ===
2+
function Foo() {}
3+
>Foo : () => void
4+
5+
const a = /* @type string */(Foo);
6+
>a : () => void
7+
>(Foo) : () => void
8+
>Foo : () => void
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @allowJS: true
2+
// @outDir: ./out
3+
// @filename: index.js
4+
function Foo() {}
5+
const a = /* @type string */(Foo);

0 commit comments

Comments
 (0)