-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8452 from Microsoft/equalityUndefinedAndNull
Allow equality comparisons to undefined and null in strict null checking mode
- Loading branch information
Showing
4 changed files
with
299 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts(60,9): error TS2365: Operator '>' cannot be applied to types 'number' and 'undefined'. | ||
tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts(62,9): error TS2365: Operator '<' cannot be applied to types 'number' and 'undefined'. | ||
tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts(64,9): error TS2365: Operator '>=' cannot be applied to types 'number' and 'undefined'. | ||
tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts(66,9): error TS2365: Operator '<=' cannot be applied to types 'number' and 'undefined'. | ||
|
||
|
||
==== tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts (4 errors) ==== | ||
|
||
function f1(x: string) { | ||
if (x == undefined) { | ||
} | ||
if (x != undefined) { | ||
} | ||
if (x === undefined) { | ||
} | ||
if (x !== undefined) { | ||
} | ||
if (x == null) { | ||
} | ||
if (x != null) { | ||
} | ||
if (x === null) { | ||
} | ||
if (x !== null) { | ||
} | ||
if (undefined == x) { | ||
} | ||
if (undefined != x) { | ||
} | ||
if (undefined === x) { | ||
} | ||
if (undefined !== x) { | ||
} | ||
if (null == x) { | ||
} | ||
if (null != x) { | ||
} | ||
if (null === x) { | ||
} | ||
if (null !== x) { | ||
} | ||
} | ||
|
||
function f2() { | ||
if (undefined == undefined) { | ||
} | ||
if (undefined == null) { | ||
} | ||
if (null == undefined) { | ||
} | ||
if (null == null) { | ||
} | ||
} | ||
|
||
function f3(a: number, b: boolean, c: { x: number }, d: number | string) { | ||
if (a == null) { | ||
} | ||
if (b == null) { | ||
} | ||
if (c == null) { | ||
} | ||
if (d == null) { | ||
} | ||
} | ||
|
||
function f4(x: number) { | ||
if (x > undefined) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2365: Operator '>' cannot be applied to types 'number' and 'undefined'. | ||
} | ||
if (x < undefined) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2365: Operator '<' cannot be applied to types 'number' and 'undefined'. | ||
} | ||
if (x >= undefined) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2365: Operator '>=' cannot be applied to types 'number' and 'undefined'. | ||
} | ||
if (x <= undefined) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2365: Operator '<=' cannot be applied to types 'number' and 'undefined'. | ||
} | ||
} | ||
|
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,136 @@ | ||
//// [equalityStrictNulls.ts] | ||
|
||
function f1(x: string) { | ||
if (x == undefined) { | ||
} | ||
if (x != undefined) { | ||
} | ||
if (x === undefined) { | ||
} | ||
if (x !== undefined) { | ||
} | ||
if (x == null) { | ||
} | ||
if (x != null) { | ||
} | ||
if (x === null) { | ||
} | ||
if (x !== null) { | ||
} | ||
if (undefined == x) { | ||
} | ||
if (undefined != x) { | ||
} | ||
if (undefined === x) { | ||
} | ||
if (undefined !== x) { | ||
} | ||
if (null == x) { | ||
} | ||
if (null != x) { | ||
} | ||
if (null === x) { | ||
} | ||
if (null !== x) { | ||
} | ||
} | ||
|
||
function f2() { | ||
if (undefined == undefined) { | ||
} | ||
if (undefined == null) { | ||
} | ||
if (null == undefined) { | ||
} | ||
if (null == null) { | ||
} | ||
} | ||
|
||
function f3(a: number, b: boolean, c: { x: number }, d: number | string) { | ||
if (a == null) { | ||
} | ||
if (b == null) { | ||
} | ||
if (c == null) { | ||
} | ||
if (d == null) { | ||
} | ||
} | ||
|
||
function f4(x: number) { | ||
if (x > undefined) { | ||
} | ||
if (x < undefined) { | ||
} | ||
if (x >= undefined) { | ||
} | ||
if (x <= undefined) { | ||
} | ||
} | ||
|
||
|
||
//// [equalityStrictNulls.js] | ||
function f1(x) { | ||
if (x == undefined) { | ||
} | ||
if (x != undefined) { | ||
} | ||
if (x === undefined) { | ||
} | ||
if (x !== undefined) { | ||
} | ||
if (x == null) { | ||
} | ||
if (x != null) { | ||
} | ||
if (x === null) { | ||
} | ||
if (x !== null) { | ||
} | ||
if (undefined == x) { | ||
} | ||
if (undefined != x) { | ||
} | ||
if (undefined === x) { | ||
} | ||
if (undefined !== x) { | ||
} | ||
if (null == x) { | ||
} | ||
if (null != x) { | ||
} | ||
if (null === x) { | ||
} | ||
if (null !== x) { | ||
} | ||
} | ||
function f2() { | ||
if (undefined == undefined) { | ||
} | ||
if (undefined == null) { | ||
} | ||
if (null == undefined) { | ||
} | ||
if (null == null) { | ||
} | ||
} | ||
function f3(a, b, c, d) { | ||
if (a == null) { | ||
} | ||
if (b == null) { | ||
} | ||
if (c == null) { | ||
} | ||
if (d == null) { | ||
} | ||
} | ||
function f4(x) { | ||
if (x > undefined) { | ||
} | ||
if (x < undefined) { | ||
} | ||
if (x >= undefined) { | ||
} | ||
if (x <= undefined) { | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
tests/cases/conformance/types/typeRelationships/comparable/equalityStrictNulls.ts
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,69 @@ | ||
// @strictNullChecks: true | ||
|
||
function f1(x: string) { | ||
if (x == undefined) { | ||
} | ||
if (x != undefined) { | ||
} | ||
if (x === undefined) { | ||
} | ||
if (x !== undefined) { | ||
} | ||
if (x == null) { | ||
} | ||
if (x != null) { | ||
} | ||
if (x === null) { | ||
} | ||
if (x !== null) { | ||
} | ||
if (undefined == x) { | ||
} | ||
if (undefined != x) { | ||
} | ||
if (undefined === x) { | ||
} | ||
if (undefined !== x) { | ||
} | ||
if (null == x) { | ||
} | ||
if (null != x) { | ||
} | ||
if (null === x) { | ||
} | ||
if (null !== x) { | ||
} | ||
} | ||
|
||
function f2() { | ||
if (undefined == undefined) { | ||
} | ||
if (undefined == null) { | ||
} | ||
if (null == undefined) { | ||
} | ||
if (null == null) { | ||
} | ||
} | ||
|
||
function f3(a: number, b: boolean, c: { x: number }, d: number | string) { | ||
if (a == null) { | ||
} | ||
if (b == null) { | ||
} | ||
if (c == null) { | ||
} | ||
if (d == null) { | ||
} | ||
} | ||
|
||
function f4(x: number) { | ||
if (x > undefined) { | ||
} | ||
if (x < undefined) { | ||
} | ||
if (x >= undefined) { | ||
} | ||
if (x <= undefined) { | ||
} | ||
} |