Skip to content

Commit 16a4997

Browse files
authored
Fix 18224 (#18259) (#18292)
* Probably fix 18224 * Corrected test
1 parent 0ff8eeb commit 16a4997

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
@@ -18034,7 +18034,7 @@ namespace ts {
1803418034

1803518035
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
1803618036
if (isInJavaScriptFile(node) && node.jsDoc) {
18037-
const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag));
18037+
const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag && !!(tag as JSDocTypeTag).typeExpression && !!(tag as JSDocTypeTag).typeExpression.type));
1803818038
if (typecasts && typecasts.length) {
1803918039
// We should have already issued an error if there were multiple type jsdocs
1804018040
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)