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:
varx: string|number="hello";vary: number=10;varz: string|number=-1;if(x<y&&x<=z){}The question is: is this still desirable behavior?
Anders Hejlsberg (@ahejlsberg)Ryan Cavanaugh (@RyanCavanaugh)Dan Quirk (@danquirk)Mohamed Hegazy (@mhegazy)Jason Freeman (@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?
Anders Hejlsberg (@ahejlsberg)Ryan Cavanaugh (@RyanCavanaugh)Dan Quirk (@danquirk)Mohamed Hegazy (@mhegazy)Jason Freeman (@JsonFreeman)