To quote 4.19.1 of the spec:
4.19.3 The <, >, <=, >=, ==, !=, ===, and !== operators
These operators require one or both of the operand types to be assignable to the other. The result is always of the Boolean primitive type.
|
Any |
Boolean |
Number |
String |
Other |
| Any |
Boolean |
Boolean |
Boolean |
Boolean |
Boolean |
| Boolean |
Boolean |
Boolean |
|
|
|
| Number |
Boolean |
|
Boolean |
|
|
| String |
Boolean |
|
|
Boolean |
|
| Other |
Boolean |
|
|
|
Boolean |
This has probably unintended consequences in the case of union types:
var x: string | number = "hello";
var y: number = 10;
var z: string | number = -1;
if (x < y && x <= z) {
}
The question is: is this still desirable behavior?
@ahejlsberg @RyanCavanaugh @danquirk @mhegazy @JsonFreeman
To quote 4.19.1 of the spec:
This has probably unintended consequences in the case of union types:
The question is: is this still desirable behavior?
@ahejlsberg @RyanCavanaugh @danquirk @mhegazy @JsonFreeman