mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Reuse operandType in checkPrefixUnaryExpression (#53682)
This commit is contained in:
parent
287ee41cf2
commit
7f6376794e
@ -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 :
|
||||
|
||||
@ -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.
|
||||
|
||||
6
tests/baselines/reference/nestedUnaryExpressionHang.js
Normal file
6
tests/baselines/reference/nestedUnaryExpressionHang.js
Normal file
@ -0,0 +1,6 @@
|
||||
//// [nestedUnaryExpressionHang.ts]
|
||||
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
|
||||
//// [nestedUnaryExpressionHang.js]
|
||||
3333 % !!!!!!!!!!!!!!!!!!!!!!!!!!!!;
|
||||
@ -0,0 +1,4 @@
|
||||
=== tests/cases/compiler/nestedUnaryExpressionHang.ts ===
|
||||
|
||||
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
35
tests/baselines/reference/nestedUnaryExpressionHang.types
Normal file
35
tests/baselines/reference/nestedUnaryExpressionHang.types
Normal 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
|
||||
|
||||
1
tests/cases/compiler/nestedUnaryExpressionHang.ts
Normal file
1
tests/cases/compiler/nestedUnaryExpressionHang.ts
Normal file
@ -0,0 +1 @@
|
||||
3333%!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
Loading…
x
Reference in New Issue
Block a user