Skip to content

Commit 91b9700

Browse files
committed
Modifying tests and accepting new baselines
1 parent 008e36b commit 91b9700

18 files changed

+448
-384
lines changed

tests/baselines/reference/typeGuardOfFormTypeOfBoolean.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ var c: C;
1717
// where s is a string literal with the value 'string', 'number', or 'boolean',
1818
// - when true, narrows the type of x to the given primitive type, or
1919
// - when false, removes the primitive type from the type of x.
20-
if (typeof strOrNum === "boolean") {
21-
bool = strOrNum; // boolean
22-
}
23-
else {
24-
var z: string | number = strOrNum; // string | number
25-
}
2620
if (typeof strOrBool === "boolean") {
2721
bool = strOrBool; // boolean
2822
}
@@ -48,15 +42,18 @@ else {
4842
c = boolOrC; // C
4943
}
5044

51-
// A type guard of the form typeof x !== s, where s is a string literal,
52-
// - when true, narrows the type of x by typeof x === s when false, or
53-
// - when false, narrows the type of x by typeof x === s when true.
54-
if (typeof strOrNum !== "boolean") {
55-
var z: string | number = strOrNum; // string | number
45+
// Narrowing occurs only if target type is a subtype of variable type
46+
if (typeof strOrNum === "boolean") {
47+
var z1: string | number = strOrNum; // string | number
5648
}
5749
else {
58-
bool = strOrNum; // boolean
50+
var z2: string | number = strOrNum; // string | number
5951
}
52+
53+
54+
// A type guard of the form typeof x !== s, where s is a string literal,
55+
// - when true, narrows the type of x by typeof x === s when false, or
56+
// - when false, narrows the type of x by typeof x === s when true.
6057
if (typeof strOrBool !== "boolean") {
6158
str = strOrBool; // string
6259
}
@@ -80,7 +77,16 @@ if (typeof boolOrC !== "boolean") {
8077
}
8178
else {
8279
bool = boolOrC; // boolean
83-
}
80+
}
81+
82+
// Narrowing occurs only if target type is a subtype of variable type
83+
if (typeof strOrNum !== "boolean") {
84+
var z1: string | number = strOrNum; // string | number
85+
}
86+
else {
87+
var z2: string | number = strOrNum; // string | number
88+
}
89+
8490

8591
//// [typeGuardOfFormTypeOfBoolean.js]
8692
var C = (function () {
@@ -104,12 +110,6 @@ var c;
104110
// where s is a string literal with the value 'string', 'number', or 'boolean',
105111
// - when true, narrows the type of x to the given primitive type, or
106112
// - when false, removes the primitive type from the type of x.
107-
if (typeof strOrNum === "boolean") {
108-
bool = strOrNum; // boolean
109-
}
110-
else {
111-
var z = strOrNum; // string | number
112-
}
113113
if (typeof strOrBool === "boolean") {
114114
bool = strOrBool; // boolean
115115
}
@@ -134,15 +134,16 @@ if (typeof boolOrC === "boolean") {
134134
else {
135135
c = boolOrC; // C
136136
}
137-
// A type guard of the form typeof x !== s, where s is a string literal,
138-
// - when true, narrows the type of x by typeof x === s when false, or
139-
// - when false, narrows the type of x by typeof x === s when true.
140-
if (typeof strOrNum !== "boolean") {
141-
var z = strOrNum; // string | number
137+
// Narrowing occurs only if target type is a subtype of variable type
138+
if (typeof strOrNum === "boolean") {
139+
var z1 = strOrNum; // string | number
142140
}
143141
else {
144-
bool = strOrNum; // boolean
142+
var z2 = strOrNum; // string | number
145143
}
144+
// A type guard of the form typeof x !== s, where s is a string literal,
145+
// - when true, narrows the type of x by typeof x === s when false, or
146+
// - when false, narrows the type of x by typeof x === s when true.
146147
if (typeof strOrBool !== "boolean") {
147148
str = strOrBool; // string
148149
}
@@ -167,3 +168,10 @@ if (typeof boolOrC !== "boolean") {
167168
else {
168169
bool = boolOrC; // boolean
169170
}
171+
// Narrowing occurs only if target type is a subtype of variable type
172+
if (typeof strOrNum !== "boolean") {
173+
var z1 = strOrNum; // string | number
174+
}
175+
else {
176+
var z2 = strOrNum; // string | number
177+
}

tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ var c: C;
4444
// where s is a string literal with the value 'string', 'number', or 'boolean',
4545
// - when true, narrows the type of x to the given primitive type, or
4646
// - when false, removes the primitive type from the type of x.
47-
if (typeof strOrNum === "boolean") {
48-
>typeof strOrNum === "boolean" : boolean
49-
>typeof strOrNum : string
50-
>strOrNum : string | number
51-
52-
bool = strOrNum; // boolean
53-
>bool = strOrNum : boolean
54-
>bool : boolean
55-
>strOrNum : boolean
56-
}
57-
else {
58-
var z: string | number = strOrNum; // string | number
59-
>z : string | number
60-
>strOrNum : string | number
61-
}
6247
if (typeof strOrBool === "boolean") {
6348
>typeof strOrBool === "boolean" : boolean
6449
>typeof strOrBool : string
@@ -124,24 +109,26 @@ else {
124109
>boolOrC : C
125110
}
126111

127-
// A type guard of the form typeof x !== s, where s is a string literal,
128-
// - when true, narrows the type of x by typeof x === s when false, or
129-
// - when false, narrows the type of x by typeof x === s when true.
130-
if (typeof strOrNum !== "boolean") {
131-
>typeof strOrNum !== "boolean" : boolean
112+
// Narrowing occurs only if target type is a subtype of variable type
113+
if (typeof strOrNum === "boolean") {
114+
>typeof strOrNum === "boolean" : boolean
132115
>typeof strOrNum : string
133116
>strOrNum : string | number
134117

135-
var z: string | number = strOrNum; // string | number
136-
>z : string | number
118+
var z1: string | number = strOrNum; // string | number
119+
>z1 : string | number
137120
>strOrNum : string | number
138121
}
139122
else {
140-
bool = strOrNum; // boolean
141-
>bool = strOrNum : boolean
142-
>bool : boolean
143-
>strOrNum : boolean
123+
var z2: string | number = strOrNum; // string | number
124+
>z2 : string | number
125+
>strOrNum : string | number
144126
}
127+
128+
129+
// A type guard of the form typeof x !== s, where s is a string literal,
130+
// - when true, narrows the type of x by typeof x === s when false, or
131+
// - when false, narrows the type of x by typeof x === s when true.
145132
if (typeof strOrBool !== "boolean") {
146133
>typeof strOrBool !== "boolean" : boolean
147134
>typeof strOrBool : string
@@ -206,3 +193,20 @@ else {
206193
>bool : boolean
207194
>boolOrC : boolean
208195
}
196+
197+
// Narrowing occurs only if target type is a subtype of variable type
198+
if (typeof strOrNum !== "boolean") {
199+
>typeof strOrNum !== "boolean" : boolean
200+
>typeof strOrNum : string
201+
>strOrNum : string | number
202+
203+
var z1: string | number = strOrNum; // string | number
204+
>z1 : string | number
205+
>strOrNum : string | number
206+
}
207+
else {
208+
var z2: string | number = strOrNum; // string | number
209+
>z2 : string | number
210+
>strOrNum : string | number
211+
}
212+

tests/baselines/reference/typeGuardOfFormTypeOfNumber.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ if (typeof strOrNum === "number") {
2323
else {
2424
str === strOrNum; // string
2525
}
26-
if (typeof strOrBool === "number") {
27-
num = strOrBool; // number
28-
}
29-
else {
30-
var y: string | boolean = strOrBool; // string | boolean
31-
}
3226
if (typeof numOrBool === "number") {
3327
num = numOrBool; // number
3428
}
@@ -48,6 +42,14 @@ else {
4842
c = numOrC; // C
4943
}
5044

45+
// Narrowing occurs only if target type is a subtype of variable type
46+
if (typeof strOrBool === "number") {
47+
var y1: string | boolean = strOrBool; // string | boolean
48+
}
49+
else {
50+
var y2: string | boolean = strOrBool; // string | boolean
51+
}
52+
5153
// A type guard of the form typeof x !== s, where s is a string literal,
5254
// - when true, narrows the type of x by typeof x === s when false, or
5355
// - when false, narrows the type of x by typeof x === s when true.
@@ -57,12 +59,6 @@ if (typeof strOrNum !== "number") {
5759
else {
5860
num = strOrNum; // number
5961
}
60-
if (typeof strOrBool !== "number") {
61-
var y: string | boolean = strOrBool; // string | boolean
62-
}
63-
else {
64-
num = strOrBool; // number
65-
}
6662
if (typeof numOrBool !== "number") {
6763
var x: number | boolean = numOrBool; // number | boolean
6864
}
@@ -80,7 +76,16 @@ if (typeof numOrC !== "number") {
8076
}
8177
else {
8278
num = numOrC; // number
83-
}
79+
}
80+
81+
// Narrowing occurs only if target type is a subtype of variable type
82+
if (typeof strOrBool !== "number") {
83+
var y1: string | boolean = strOrBool; // string | boolean
84+
}
85+
else {
86+
var y2: string | boolean = strOrBool; // string | boolean
87+
}
88+
8489

8590
//// [typeGuardOfFormTypeOfNumber.js]
8691
var C = (function () {
@@ -110,12 +115,6 @@ if (typeof strOrNum === "number") {
110115
else {
111116
str === strOrNum; // string
112117
}
113-
if (typeof strOrBool === "number") {
114-
num = strOrBool; // number
115-
}
116-
else {
117-
var y = strOrBool; // string | boolean
118-
}
119118
if (typeof numOrBool === "number") {
120119
num = numOrBool; // number
121120
}
@@ -134,6 +133,13 @@ if (typeof numOrC === "number") {
134133
else {
135134
c = numOrC; // C
136135
}
136+
// Narrowing occurs only if target type is a subtype of variable type
137+
if (typeof strOrBool === "number") {
138+
var y1 = strOrBool; // string | boolean
139+
}
140+
else {
141+
var y2 = strOrBool; // string | boolean
142+
}
137143
// A type guard of the form typeof x !== s, where s is a string literal,
138144
// - when true, narrows the type of x by typeof x === s when false, or
139145
// - when false, narrows the type of x by typeof x === s when true.
@@ -143,12 +149,6 @@ if (typeof strOrNum !== "number") {
143149
else {
144150
num = strOrNum; // number
145151
}
146-
if (typeof strOrBool !== "number") {
147-
var y = strOrBool; // string | boolean
148-
}
149-
else {
150-
num = strOrBool; // number
151-
}
152152
if (typeof numOrBool !== "number") {
153153
var x = numOrBool; // number | boolean
154154
}
@@ -167,3 +167,10 @@ if (typeof numOrC !== "number") {
167167
else {
168168
num = numOrC; // number
169169
}
170+
// Narrowing occurs only if target type is a subtype of variable type
171+
if (typeof strOrBool !== "number") {
172+
var y1 = strOrBool; // string | boolean
173+
}
174+
else {
175+
var y2 = strOrBool; // string | boolean
176+
}

tests/baselines/reference/typeGuardOfFormTypeOfNumber.types

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,6 @@ else {
6060
>str : string
6161
>strOrNum : string
6262
}
63-
if (typeof strOrBool === "number") {
64-
>typeof strOrBool === "number" : boolean
65-
>typeof strOrBool : string
66-
>strOrBool : string | boolean
67-
68-
num = strOrBool; // number
69-
>num = strOrBool : number
70-
>num : number
71-
>strOrBool : number
72-
}
73-
else {
74-
var y: string | boolean = strOrBool; // string | boolean
75-
>y : string | boolean
76-
>strOrBool : string | boolean
77-
}
7863
if (typeof numOrBool === "number") {
7964
>typeof numOrBool === "number" : boolean
8065
>typeof numOrBool : string
@@ -123,6 +108,22 @@ else {
123108
>numOrC : C
124109
}
125110

111+
// Narrowing occurs only if target type is a subtype of variable type
112+
if (typeof strOrBool === "number") {
113+
>typeof strOrBool === "number" : boolean
114+
>typeof strOrBool : string
115+
>strOrBool : string | boolean
116+
117+
var y1: string | boolean = strOrBool; // string | boolean
118+
>y1 : string | boolean
119+
>strOrBool : string | boolean
120+
}
121+
else {
122+
var y2: string | boolean = strOrBool; // string | boolean
123+
>y2 : string | boolean
124+
>strOrBool : string | boolean
125+
}
126+
126127
// A type guard of the form typeof x !== s, where s is a string literal,
127128
// - when true, narrows the type of x by typeof x === s when false, or
128129
// - when false, narrows the type of x by typeof x === s when true.
@@ -142,21 +143,6 @@ else {
142143
>num : number
143144
>strOrNum : number
144145
}
145-
if (typeof strOrBool !== "number") {
146-
>typeof strOrBool !== "number" : boolean
147-
>typeof strOrBool : string
148-
>strOrBool : string | boolean
149-
150-
var y: string | boolean = strOrBool; // string | boolean
151-
>y : string | boolean
152-
>strOrBool : string | boolean
153-
}
154-
else {
155-
num = strOrBool; // number
156-
>num = strOrBool : number
157-
>num : number
158-
>strOrBool : number
159-
}
160146
if (typeof numOrBool !== "number") {
161147
>typeof numOrBool !== "number" : boolean
162148
>typeof numOrBool : string
@@ -204,3 +190,20 @@ else {
204190
>num : number
205191
>numOrC : number
206192
}
193+
194+
// Narrowing occurs only if target type is a subtype of variable type
195+
if (typeof strOrBool !== "number") {
196+
>typeof strOrBool !== "number" : boolean
197+
>typeof strOrBool : string
198+
>strOrBool : string | boolean
199+
200+
var y1: string | boolean = strOrBool; // string | boolean
201+
>y1 : string | boolean
202+
>strOrBool : string | boolean
203+
}
204+
else {
205+
var y2: string | boolean = strOrBool; // string | boolean
206+
>y2 : string | boolean
207+
>strOrBool : string | boolean
208+
}
209+

0 commit comments

Comments
 (0)