Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Spelling
- Loading branch information
1 parent
95413f0
commit 0949ad1
Showing
6 changed files
with
506 additions
and
1 deletion.
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,71 @@ | ||
tests/cases/compiler/narrowByEquality.ts(53,15): error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/compiler/narrowByEquality.ts(54,9): error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
Type 'string' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/narrowByEquality.ts (2 errors) ==== | ||
declare let x: number | string | boolean | ||
declare let n: number; | ||
declare let s: string; | ||
declare let b: boolean; | ||
|
||
if (x == n) { | ||
x; | ||
} | ||
|
||
if (x == s) { | ||
x; | ||
} | ||
|
||
if (x == b) { | ||
x; | ||
} | ||
|
||
if (x == 1) { | ||
x; | ||
} | ||
|
||
if (x == "") { | ||
x; | ||
} | ||
|
||
if (x == "foo") { | ||
x; | ||
} | ||
|
||
if (x == true) { | ||
x; | ||
} | ||
|
||
if (x == false) { | ||
x; | ||
} | ||
|
||
declare let xAndObj: number | string | boolean | object | ||
|
||
if (xAndObj == {}) { | ||
xAndObj; | ||
} | ||
|
||
if (x == xAndObj) { | ||
x; | ||
xAndObj; | ||
} | ||
|
||
// Repro from #24991 | ||
|
||
function test(level: number | string):number { | ||
if (level == +level) { | ||
const q2: number = level; // error | ||
~~ | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
return level; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number'. | ||
} | ||
return 0; | ||
} | ||
|
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,101 @@ | ||
//// [narrowByEquality.ts] | ||
declare let x: number | string | boolean | ||
declare let n: number; | ||
declare let s: string; | ||
declare let b: boolean; | ||
|
||
if (x == n) { | ||
x; | ||
} | ||
|
||
if (x == s) { | ||
x; | ||
} | ||
|
||
if (x == b) { | ||
x; | ||
} | ||
|
||
if (x == 1) { | ||
x; | ||
} | ||
|
||
if (x == "") { | ||
x; | ||
} | ||
|
||
if (x == "foo") { | ||
x; | ||
} | ||
|
||
if (x == true) { | ||
x; | ||
} | ||
|
||
if (x == false) { | ||
x; | ||
} | ||
|
||
declare let xAndObj: number | string | boolean | object | ||
|
||
if (xAndObj == {}) { | ||
xAndObj; | ||
} | ||
|
||
if (x == xAndObj) { | ||
x; | ||
xAndObj; | ||
} | ||
|
||
// Repro from #24991 | ||
|
||
function test(level: number | string):number { | ||
if (level == +level) { | ||
const q2: number = level; // error | ||
return level; | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
//// [narrowByEquality.js] | ||
"use strict"; | ||
if (x == n) { | ||
x; | ||
} | ||
if (x == s) { | ||
x; | ||
} | ||
if (x == b) { | ||
x; | ||
} | ||
if (x == 1) { | ||
x; | ||
} | ||
if (x == "") { | ||
x; | ||
} | ||
if (x == "foo") { | ||
x; | ||
} | ||
if (x == true) { | ||
x; | ||
} | ||
if (x == false) { | ||
x; | ||
} | ||
if (xAndObj == {}) { | ||
xAndObj; | ||
} | ||
if (x == xAndObj) { | ||
x; | ||
xAndObj; | ||
} | ||
// Repro from #24991 | ||
function test(level) { | ||
if (level == +level) { | ||
var q2 = level; // error | ||
return level; | ||
} | ||
return 0; | ||
} |
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,113 @@ | ||
=== tests/cases/compiler/narrowByEquality.ts === | ||
declare let x: number | string | boolean | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
declare let n: number; | ||
>n : Symbol(n, Decl(narrowByEquality.ts, 1, 11)) | ||
|
||
declare let s: string; | ||
>s : Symbol(s, Decl(narrowByEquality.ts, 2, 11)) | ||
|
||
declare let b: boolean; | ||
>b : Symbol(b, Decl(narrowByEquality.ts, 3, 11)) | ||
|
||
if (x == n) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
>n : Symbol(n, Decl(narrowByEquality.ts, 1, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == s) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
>s : Symbol(s, Decl(narrowByEquality.ts, 2, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == b) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
>b : Symbol(b, Decl(narrowByEquality.ts, 3, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == 1) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == "") { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == "foo") { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == true) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
if (x == false) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
} | ||
|
||
declare let xAndObj: number | string | boolean | object | ||
>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) | ||
|
||
if (xAndObj == {}) { | ||
>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) | ||
|
||
xAndObj; | ||
>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) | ||
} | ||
|
||
if (x == xAndObj) { | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) | ||
|
||
x; | ||
>x : Symbol(x, Decl(narrowByEquality.ts, 0, 11)) | ||
|
||
xAndObj; | ||
>xAndObj : Symbol(xAndObj, Decl(narrowByEquality.ts, 37, 11)) | ||
} | ||
|
||
// Repro from #24991 | ||
|
||
function test(level: number | string):number { | ||
>test : Symbol(test, Decl(narrowByEquality.ts, 46, 1)) | ||
>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) | ||
|
||
if (level == +level) { | ||
>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) | ||
>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) | ||
|
||
const q2: number = level; // error | ||
>q2 : Symbol(q2, Decl(narrowByEquality.ts, 52, 13)) | ||
>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) | ||
|
||
return level; | ||
>level : Symbol(level, Decl(narrowByEquality.ts, 50, 14)) | ||
} | ||
return 0; | ||
} | ||
|
Oops, something went wrong.