Skip to content

Cover more literal expressions in getQuickTypeOfExpression #52181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ import {
isBlock,
isBlockOrCatchScoped,
isBlockScopedContainerTopLevel,
isBooleanLiteral,
isCallChain,
isCallExpression,
isCallLikeExpression,
Expand Down Expand Up @@ -582,6 +583,7 @@ import {
isLet,
isLineBreak,
isLiteralComputedPropertyDeclarationName,
isLiteralExpression,
isLiteralExpressionOfObject,
isLiteralImportTypeNode,
isLiteralTypeNode,
Expand Down Expand Up @@ -36505,8 +36507,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) {
return getTypeFromTypeNode((expr as TypeAssertion).type);
}
else if (node.kind === SyntaxKind.NumericLiteral || node.kind === SyntaxKind.StringLiteral ||
node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword) {
else if (isLiteralExpression(node) || isBooleanLiteral(node)) {
return checkExpression(node);
Comment on lines -36509 to 36511
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the test suite passes even if we remove this else if block entirely - leading me to believe that this is merely an optimization for those types here (as it's not an unused code ⚠️ ).

The main improvement here is to just cover every literal type - including bigints, regexps and "no substitution template literals".

Feel free to close the PR if you don't like this change.

}
return undefined;
Expand Down