Skip to content

Commit 48328ca

Browse files
authored
Cache expression type when checking assertion (#54224)
1 parent f0ff976 commit 48328ca

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/compiler/checker.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -34523,6 +34523,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3452334523
}
3452434524
return getRegularTypeOfLiteralType(exprType);
3452534525
}
34526+
const links = getNodeLinks(node);
34527+
links.assertionExpressionType = exprType;
3452634528
checkSourceElement(type);
3452734529
checkNodeDeferred(node);
3452834530
return getTypeFromTypeNode(type);
@@ -34547,9 +34549,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3454734549
}
3454834550

3454934551
function checkAssertionDeferred(node: JSDocTypeAssertion | AssertionExpression) {
34550-
const { type, expression } = getAssertionTypeAndExpression(node);
34552+
const { type } = getAssertionTypeAndExpression(node);
3455134553
const errNode = isParenthesizedExpression(node) ? type : node;
34552-
const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(checkExpression(expression)));
34554+
const links = getNodeLinks(node);
34555+
Debug.assertIsDefined(links.assertionExpressionType);
34556+
const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(links.assertionExpressionType));
3455334557
const targetType = getTypeFromTypeNode(type);
3455434558
if (!isErrorType(targetType)) {
3455534559
addLazyDiagnostic(() => {

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6060,6 +6060,7 @@ export interface NodeLinks {
60606060
spreadIndices?: { first: number | undefined, last: number | undefined }; // Indices of first and last spread elements in array literal
60616061
parameterInitializerContainsUndefined?: boolean; // True if this is a parameter declaration whose type annotation contains "undefined".
60626062
fakeScopeForSignatureDeclaration?: boolean; // True if this is a fake scope injected into an enclosing declaration chain.
6063+
assertionExpressionType?: Type; // Cached type of the expression of a type assertion
60636064
}
60646065

60656066
/** @internal */

0 commit comments

Comments
 (0)