Skip to content

Narrow string and number types in literal equality checks #11587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept new baselines
  • Loading branch information
ahejlsberg committed Oct 13, 2016
commit 57a9a6344a64f5a5a15fb1b98b2cef4acdcc620b
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function foo(a: string): string | number {

return a.length;
>a.length : number
>a : string
>a : "hello"
>length : number
}

Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/literalTypes1.types
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function f4(x: 0 | 1 | true | string) {
>"def" : "def"

x;
>x : string
>x : "abc" | "def"

break;
case null:
Expand Down Expand Up @@ -163,7 +163,7 @@ function f5(x: string | number | boolean) {
>"abc" : "abc"

x;
>x : string
>x : "abc"

break;
case 0:
Expand All @@ -173,7 +173,7 @@ function f5(x: string | number | boolean) {
>1 : 1

x;
>x : number
>x : 0 | 1

break;
case true:
Expand All @@ -190,7 +190,7 @@ function f5(x: string | number | boolean) {
>123 : 123

x;
>x : string | number
>x : "hello" | 123

break;
default:
Expand Down
6 changes: 3 additions & 3 deletions tests/baselines/reference/sourceMapValidationIfElse.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (i == 10) {

i++;
>i++ : number
>i : number
>i : 10

} else
{
Expand All @@ -22,7 +22,7 @@ if (i == 10)
{
i++;
>i++ : number
>i : number
>i : 10
}
else if (i == 20) {
>i == 20 : boolean
Expand All @@ -31,7 +31,7 @@ else if (i == 20) {

i--;
>i-- : number
>i : number
>i : 20

} else if (i == 30) {
>i == 30 : boolean
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/sourceMapValidationSwitch.types
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ switch (x) {

x++;
>x++ : number
>x : number
>x : 5

break;
case 10:
>10 : 10
{
x--;
>x-- : number
>x : number
>x : 10

break;
}
Expand All @@ -39,15 +39,15 @@ switch (x)

x++;
>x++ : number
>x : number
>x : 5

break;
case 10:
>10 : 10
{
x--;
>x-- : number
>x : number
>x : 10

break;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/sourceMapValidationWhile.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ while (a == 10) {

a++;
>a++ : number
>a : number
>a : 10
}
while (a == 10)
>a == 10 : boolean
Expand All @@ -19,5 +19,5 @@ while (a == 10)
{
a++;
>a++ : number
>a : number
>a : 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (x === "foo") {

let a = x;
>a : string
>x : string
>x : "foo"
}
else if (x !== "bar") {
>x !== "bar" : boolean
Expand All @@ -35,15 +35,15 @@ else if (x !== "bar") {
else {
let c = x;
>c : string
>x : string
>x : "bar"

let d = y;
>d : string
>y : string

let e: (typeof x) | (typeof y) = c || d;
>e : string
>x : string
>x : "bar"
>y : string
>c || d : string
>c : string
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/throwInEnclosingStatements.types
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ switch (y) {
>'a' : "a"

throw y;
>y : string
>y : "a"

default:
throw y;
Expand Down