Skip to content

Commit e852627

Browse files
committed
Add early out for type assertions in getTypeOfExpression
1 parent b5998d9 commit e852627

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21698,15 +21698,19 @@ namespace ts {
2169821698
* to cache the result.
2169921699
*/
2170021700
function getTypeOfExpression(node: Expression, cache?: boolean) {
21701+
const expr = skipParentheses(node);
2170121702
// Optimize for the common case of a call to a function with a single non-generic call
2170221703
// signature where we can just fetch the return type without checking the arguments.
21703-
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true) && !isSymbolOrSymbolForCall(node)) {
21704-
const funcType = checkNonNullExpression((<CallExpression>node).expression);
21704+
if (expr.kind === SyntaxKind.CallExpression && (<CallExpression>expr).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(expr, /*checkArgumentIsStringLiteralLike*/ true) && !isSymbolOrSymbolForCall(expr)) {
21705+
const funcType = checkNonNullExpression((<CallExpression>expr).expression);
2170521706
const signature = getSingleCallSignature(funcType);
2170621707
if (signature && !signature.typeParameters) {
2170721708
return getReturnTypeOfSignature(signature);
2170821709
}
2170921710
}
21711+
else if (expr.kind === SyntaxKind.TypeAssertionExpression || expr.kind === SyntaxKind.AsExpression) {
21712+
return getTypeFromTypeNode((<TypeAssertion>expr).type);
21713+
}
2171021714
// Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
2171121715
// should have a parameter that indicates whether full error checking is required such that
2171221716
// we can perform the optimizations locally.

0 commit comments

Comments
 (0)