@@ -8388,12 +8388,12 @@ namespace ts {
8388
8388
}
8389
8389
8390
8390
function isNullOrUndefined(node: Expression) {
8391
- const expr = skipParentheses(node);
8391
+ const expr = skipParentheses(node, /*excludeJSDocTypeAssertions*/ true );
8392
8392
return expr.kind === SyntaxKind.NullKeyword || expr.kind === SyntaxKind.Identifier && getResolvedSymbol(expr as Identifier) === undefinedSymbol;
8393
8393
}
8394
8394
8395
8395
function isEmptyArrayLiteral(node: Expression) {
8396
- const expr = skipParentheses(node);
8396
+ const expr = skipParentheses(node, /*excludeJSDocTypeAssertions*/ true );
8397
8397
return expr.kind === SyntaxKind.ArrayLiteralExpression && (expr as ArrayLiteralExpression).elements.length === 0;
8398
8398
}
8399
8399
@@ -9022,13 +9022,15 @@ namespace ts {
9022
9022
}
9023
9023
9024
9024
function tryGetTypeFromEffectiveTypeNode(declaration: Declaration) {
9025
+ if (isVariableDeclaration(declaration) && isIdentifier(declaration.name) && declaration.name.escapedText === "aaaaa") debugger;
9025
9026
const typeNode = getEffectiveTypeAnnotationNode(declaration);
9026
9027
if (typeNode) {
9027
9028
return getTypeFromTypeNode(typeNode);
9028
9029
}
9029
9030
}
9030
9031
9031
9032
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
9033
+ if (symbol.escapedName === "aaaaa") debugger;
9032
9034
const links = getSymbolLinks(symbol);
9033
9035
if (!links.type) {
9034
9036
const type = getTypeOfVariableOrParameterOrPropertyWorker(symbol);
@@ -22956,7 +22958,7 @@ namespace ts {
22956
22958
}
22957
22959
22958
22960
function isFalseExpression(expr: Expression): boolean {
22959
- const node = skipParentheses(expr);
22961
+ const node = skipParentheses(expr, /*excludeJSDocTypeAssertions*/ true );
22960
22962
return node.kind === SyntaxKind.FalseKeyword || node.kind === SyntaxKind.BinaryExpression && (
22961
22963
(node as BinaryExpression).operatorToken.kind === SyntaxKind.AmpersandAmpersandToken && (isFalseExpression((node as BinaryExpression).left) || isFalseExpression((node as BinaryExpression).right)) ||
22962
22964
(node as BinaryExpression).operatorToken.kind === SyntaxKind.BarBarToken && isFalseExpression((node as BinaryExpression).left) && isFalseExpression((node as BinaryExpression).right));
@@ -23278,7 +23280,7 @@ namespace ts {
23278
23280
}
23279
23281
23280
23282
function narrowTypeByAssertion(type: Type, expr: Expression): Type {
23281
- const node = skipParentheses(expr);
23283
+ const node = skipParentheses(expr, /*excludeJSDocTypeAssertions*/ true );
23282
23284
if (node.kind === SyntaxKind.FalseKeyword) {
23283
23285
return unreachableNeverType;
23284
23286
}
@@ -25858,7 +25860,9 @@ namespace ts {
25858
25860
case SyntaxKind.ParenthesizedExpression: {
25859
25861
// Like in `checkParenthesizedExpression`, an `/** @type {xyz} */` comment before a parenthesized expression acts as a type cast.
25860
25862
const tag = isInJSFile(parent) ? getJSDocTypeTag(parent) : undefined;
25861
- return tag ? getTypeFromTypeNode(tag.typeExpression.type) : getContextualType(parent as ParenthesizedExpression, contextFlags);
25863
+ return !tag ? getContextualType(parent as ParenthesizedExpression, contextFlags) :
25864
+ isJSDocTypeTag(tag) && isConstTypeReference(tag.typeExpression.type) ? tryFindWhenConstTypeReference(parent as ParenthesizedExpression) :
25865
+ getTypeFromTypeNode(tag.typeExpression.type);
25862
25866
}
25863
25867
case SyntaxKind.NonNullExpression:
25864
25868
return getContextualType(parent as NonNullExpression, contextFlags);
@@ -32768,8 +32772,10 @@ namespace ts {
32768
32772
}
32769
32773
32770
32774
function isTypeAssertion(node: Expression) {
32771
- node = skipParentheses(node);
32772
- return node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression;
32775
+ node = skipParentheses(node, /*excludeJSDocTypeAssertions*/ true);
32776
+ return node.kind === SyntaxKind.TypeAssertionExpression ||
32777
+ node.kind === SyntaxKind.AsExpression ||
32778
+ isJSDocTypeAssertion(node);
32773
32779
}
32774
32780
32775
32781
function checkDeclarationInitializer(declaration: HasExpressionInitializer, contextualType?: Type | undefined) {
@@ -32844,6 +32850,7 @@ namespace ts {
32844
32850
function isConstContext(node: Expression): boolean {
32845
32851
const parent = node.parent;
32846
32852
return isAssertionExpression(parent) && isConstTypeReference(parent.type) ||
32853
+ isJSDocTypeAssertion(parent) && isConstTypeReference(getJSDocTypeAssertionType(parent)) ||
32847
32854
(isParenthesizedExpression(parent) || isArrayLiteralExpression(parent) || isSpreadElement(parent)) && isConstContext(parent) ||
32848
32855
(isPropertyAssignment(parent) || isShorthandPropertyAssignment(parent) || isTemplateSpan(parent)) && isConstContext(parent.parent);
32849
32856
}
@@ -33056,7 +33063,14 @@ namespace ts {
33056
33063
}
33057
33064
33058
33065
function getQuickTypeOfExpression(node: Expression) {
33059
- const expr = skipParentheses(node);
33066
+ let expr = skipParentheses(node, /*excludeJSDocTypeAssertions*/ true);
33067
+ if (isJSDocTypeAssertion(expr)) {
33068
+ const type = getJSDocTypeAssertionType(expr);
33069
+ if (!isConstTypeReference(type)) {
33070
+ return getTypeFromTypeNode(type);
33071
+ }
33072
+ }
33073
+ expr = skipParentheses(node);
33060
33074
// Optimize for the common case of a call to a function with a single non-generic call
33061
33075
// signature where we can just fetch the return type without checking the arguments.
33062
33076
if (isCallExpression(expr) && expr.expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(expr, /*checkArgumentIsStringLiteralLike*/ true) && !isSymbolOrSymbolForCall(expr)) {
@@ -33143,9 +33157,9 @@ namespace ts {
33143
33157
}
33144
33158
33145
33159
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
33146
- const tag = isInJSFile(node) ? getJSDocTypeTag (node) : undefined;
33147
- if (tag) {
33148
- return checkAssertionWorker(tag.typeExpression. type, tag.typeExpression. type, node.expression, checkMode);
33160
+ if (isJSDocTypeAssertion (node)) {
33161
+ const type = getJSDocTypeAssertionType(node);
33162
+ return checkAssertionWorker(type, type, node.expression, checkMode);
33149
33163
}
33150
33164
return checkExpression(node.expression, checkMode);
33151
33165
}
@@ -36093,7 +36107,7 @@ namespace ts {
36093
36107
if (getFalsyFlags(type)) return;
36094
36108
36095
36109
const location = isBinaryExpression(condExpr) ? condExpr.right : condExpr;
36096
- if (isPropertyAccessExpression(location) && isAssertionExpression(skipParentheses( location.expression) )) {
36110
+ if (isPropertyAccessExpression(location) && isTypeAssertion( location.expression)) {
36097
36111
return;
36098
36112
}
36099
36113
0 commit comments