@@ -13305,8 +13305,11 @@ namespace ts {
13305
13305
case SyntaxKind.TemplateSpan:
13306
13306
Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression);
13307
13307
return getContextualTypeForSubstitutionExpression(<TemplateExpression>parent.parent, node);
13308
- case SyntaxKind.ParenthesizedExpression:
13309
- return getContextualType(<ParenthesizedExpression>parent);
13308
+ case SyntaxKind.ParenthesizedExpression: {
13309
+ // Like in `checkParenthesizedExpression`, an `/** @type {xyz} */` comment before a parenthesized expression acts as a type cast.
13310
+ const tag = isInJavaScriptFile(parent) ? getJSDocTypeTag(parent) : undefined;
13311
+ return tag ? getTypeFromTypeNode(tag.typeExpression.type) : getContextualType(<ParenthesizedExpression>parent);
13312
+ }
13310
13313
case SyntaxKind.JsxExpression:
13311
13314
return getContextualTypeForJsxExpression(<JsxExpression>parent);
13312
13315
case SyntaxKind.JsxAttribute:
@@ -18127,13 +18130,9 @@ namespace ts {
18127
18130
}
18128
18131
18129
18132
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
18130
- if (isInJavaScriptFile(node) && node.jsDoc) {
18131
- const typecasts = flatMap(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag && !!(tag as JSDocTypeTag).typeExpression && !!(tag as JSDocTypeTag).typeExpression.type));
18132
- if (typecasts && typecasts.length) {
18133
- // We should have already issued an error if there were multiple type jsdocs
18134
- const cast = typecasts[0] as JSDocTypeTag;
18135
- return checkAssertionWorker(cast, cast.typeExpression.type, node.expression, checkMode);
18136
- }
18133
+ const tag = isInJavaScriptFile(node) ? getJSDocTypeTag(node) : undefined;
18134
+ if (tag) {
18135
+ return checkAssertionWorker(tag, tag.typeExpression.type, node.expression, checkMode);
18137
18136
}
18138
18137
return checkExpression(node.expression, checkMode);
18139
18138
}
0 commit comments