Reuse operandType in checkPrefixUnaryExpression (#53682)

This commit is contained in:
Jake Bailey 2023-04-06 13:37:12 -07:00 committed by GitHub
parent 287ee41cf2
commit 7f6376794e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 1 deletions

View File

@ -36120,7 +36120,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
return getUnaryResultType(operandType);
case SyntaxKind.ExclamationToken:
checkTruthinessExpression(node.operand);
checkTruthinessOfType(operandType, node.operand);
const facts = getTypeFacts(operandType) & (TypeFacts.Truthy | TypeFacts.Falsy);
return facts === TypeFacts.Truthy ? falseType :
facts === TypeFacts.Falsy ? trueType :

View File

@ -0,0 +1,11 @@
tests/cases/compiler/nestedUnaryExpressionHang.ts(1,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/compiler/nestedUnaryExpressionHang.ts(1,34): error TS1109: Expression expected.
==== tests/cases/compiler/nestedUnaryExpressionHang.ts (2 errors) ====
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
!!! error TS1109: Expression expected.

View File

@ -0,0 +1,6 @@
//// [nestedUnaryExpressionHang.ts]
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//// [nestedUnaryExpressionHang.js]
3333 % !!!!!!!!!!!!!!!!!!!!!!!!!!!!;

View File

@ -0,0 +1,4 @@
=== tests/cases/compiler/nestedUnaryExpressionHang.ts ===
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -0,0 +1,35 @@
=== tests/cases/compiler/nestedUnaryExpressionHang.ts ===
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!! : number
>3333 : 3333
>!!!!!!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!!! : boolean
>!!!!!!!!!!!! : boolean
>!!!!!!!!!!! : boolean
>!!!!!!!!!! : boolean
>!!!!!!!!! : boolean
>!!!!!!!! : boolean
>!!!!!!! : boolean
>!!!!!! : boolean
>!!!!! : boolean
>!!!! : boolean
>!!! : boolean
>!! : boolean
>! : boolean
> : any

View File

@ -0,0 +1 @@
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!