-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve comparison operators type checking to disallow unions contain…
…ing numbers as an operand (#52048)
- Loading branch information
Showing
7 changed files
with
255 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/comparisonOperatorWithNumberOperand.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumberOperand.ts(3,1): error TS2365: Operator '>=' cannot be applied to types 'number | Promise<number>' and 'number'. | ||
|
||
|
||
==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumberOperand.ts (1 errors) ==== | ||
// repro #52036 | ||
declare const t1: number | Promise<number> | ||
t1 >= 0 // error | ||
~~~~~~~ | ||
!!! error TS2365: Operator '>=' cannot be applied to types 'number | Promise<number>' and 'number'. | ||
!!! related TS2773 tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumberOperand.ts:3:1: Did you forget to use 'await'? | ||
|
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/comparisonOperatorWithNumberOperand.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumberOperand.ts === | ||
// repro #52036 | ||
declare const t1: number | Promise<number> | ||
>t1 : Symbol(t1, Decl(comparisonOperatorWithNumberOperand.ts, 1, 13)) | ||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) | ||
|
||
t1 >= 0 // error | ||
>t1 : Symbol(t1, Decl(comparisonOperatorWithNumberOperand.ts, 1, 13)) | ||
|
10 changes: 10 additions & 0 deletions
10
tests/baselines/reference/comparisonOperatorWithNumberOperand.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumberOperand.ts === | ||
// repro #52036 | ||
declare const t1: number | Promise<number> | ||
>t1 : number | Promise<number> | ||
|
||
t1 >= 0 // error | ||
>t1 >= 0 : boolean | ||
>t1 : number | Promise<number> | ||
>0 : 0 | ||
|
Oops, something went wrong.