Skip to content

Commit fe1854e

Browse files
committed
Accept new baselines
1 parent 9277b3f commit fe1854e

5 files changed

+585
-10
lines changed

tests/baselines/reference/controlFlowBinaryOrExpression.symbols

Lines changed: 6 additions & 6 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -64,19 +64,19 @@ if (isNodeList(sourceObj)) {
64
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
64
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
65

65

66
sourceObj.length;
66
sourceObj.length;
67-
>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
67+
>sourceObj.length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
68
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
68
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
69-
>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
69+
>length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
70
}
70
}
71

71

72
if (isHTMLCollection(sourceObj)) {
72
if (isHTMLCollection(sourceObj)) {
73
>isHTMLCollection : Symbol(isHTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 18, 67))
73
>isHTMLCollection : Symbol(isHTMLCollection, Decl(controlFlowBinaryOrExpression.ts, 18, 67))
74
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
74
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
75

75

76
sourceObj.length;
76
sourceObj.length;
77-
>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
77+
>sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33))
78
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
78
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
79-
>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
79+
>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33))
80
}
80
}
81

81

82
if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
82
if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
@@ -86,8 +86,8 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
86
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
86
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
87

87

88
sourceObj.length;
88
sourceObj.length;
89-
>sourceObj.length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
89+
>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
90
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
90
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
91-
>length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
91+
>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
92
}
92
}
93

93

tests/baselines/reference/controlFlowBinaryOrExpression.types

Lines changed: 4 additions & 4 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -80,7 +80,7 @@ if (isNodeList(sourceObj)) {
80

80

81
sourceObj.length;
81
sourceObj.length;
82
>sourceObj.length : number
82
>sourceObj.length : number
83-
>sourceObj : NodeList | HTMLCollection
83+
>sourceObj : NodeList
84
>length : number
84
>length : number
85
}
85
}
86

86

@@ -91,7 +91,7 @@ if (isHTMLCollection(sourceObj)) {
91

91

92
sourceObj.length;
92
sourceObj.length;
93
>sourceObj.length : number
93
>sourceObj.length : number
94-
>sourceObj : NodeList | HTMLCollection
94+
>sourceObj : HTMLCollection
95
>length : number
95
>length : number
96
}
96
}
97

97

@@ -102,11 +102,11 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
102
>sourceObj : EventTargetLike
102
>sourceObj : EventTargetLike
103
>isHTMLCollection(sourceObj) : boolean
103
>isHTMLCollection(sourceObj) : boolean
104
>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection
104
>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection
105-
>sourceObj : { a: string; }
105+
>sourceObj : HTMLCollection | { a: string; }
106

106

107
sourceObj.length;
107
sourceObj.length;
108
>sourceObj.length : number
108
>sourceObj.length : number
109-
>sourceObj : NodeList
109+
>sourceObj : NodeList | HTMLCollection
110
>length : number
110
>length : number
111
}
111
}
112

112

Lines changed: 172 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//// [instanceofWithStructurallyIdenticalTypes.ts]
2+
// Repro from #7271
3+
4+
class C1 { item: string }
5+
class C2 { item: string[] }
6+
class C3 { item: string }
7+
8+
function foo1(x: C1 | C2 | C3): string {
9+
if (x instanceof C1) {
10+
return x.item;
11+
}
12+
else if (x instanceof C2) {
13+
return x.item[0];
14+
}
15+
else if (x instanceof C3) {
16+
return x.item;
17+
}
18+
return "error";
19+
}
20+
21+
function isC1(c: C1 | C2 | C3): c is C1 { return c instanceof C1 }
22+
function isC2(c: C1 | C2 | C3): c is C2 { return c instanceof C2 }
23+
function isC3(c: C1 | C2 | C3): c is C3 { return c instanceof C3 }
24+
25+
function foo2(x: C1 | C2 | C3): string {
26+
if (isC1(x)) {
27+
return x.item;
28+
}
29+
else if (isC2(x)) {
30+
return x.item[0];
31+
}
32+
else if (isC3(x)) {
33+
return x.item;
34+
}
35+
return "error";
36+
}
37+
38+
// More tests
39+
40+
class A { a: string }
41+
class A1 extends A { }
42+
class A2 { a: string }
43+
class B extends A { b: string }
44+
45+
function goo(x: A) {
46+
if (x instanceof A) {
47+
x; // A
48+
}
49+
else {
50+
x; // never
51+
}
52+
if (x instanceof A1) {
53+
x; // A1
54+
}
55+
else {
56+
x; // A
57+
}
58+
if (x instanceof A2) {
59+
x; // A2
60+
}
61+
else {
62+
x; // A
63+
}
64+
if (x instanceof B) {
65+
x; // B
66+
}
67+
else {
68+
x; // A
69+
}
70+
}
71+
72+
73+
//// [instanceofWithStructurallyIdenticalTypes.js]
74+
// Repro from #7271
75+
var __extends = (this && this.__extends) || function (d, b) {
76+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
77+
function __() { this.constructor = d; }
78+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
79+
};
80+
var C1 = (function () {
81+
function C1() {
82+
}
83+
return C1;
84+
}());
85+
var C2 = (function () {
86+
function C2() {
87+
}
88+
return C2;
89+
}());
90+
var C3 = (function () {
91+
function C3() {
92+
}
93+
return C3;
94+
}());
95+
function foo1(x) {
96+
if (x instanceof C1) {
97+
return x.item;
98+
}
99+
else if (x instanceof C2) {
100+
return x.item[0];
101+
}
102+
else if (x instanceof C3) {
103+
return x.item;
104+
}
105+
return "error";
106+
}
107+
function isC1(c) { return c instanceof C1; }
108+
function isC2(c) { return c instanceof C2; }
109+
function isC3(c) { return c instanceof C3; }
110+
function foo2(x) {
111+
if (isC1(x)) {
112+
return x.item;
113+
}
114+
else if (isC2(x)) {
115+
return x.item[0];
116+
}
117+
else if (isC3(x)) {
118+
return x.item;
119+
}
120+
return "error";
121+
}
122+
// More tests
123+
var A = (function () {
124+
function A() {
125+
}
126+
return A;
127+
}());
128+
var A1 = (function (_super) {
129+
__extends(A1, _super);
130+
function A1() {
131+
_super.apply(this, arguments);
132+
}
133+
return A1;
134+
}(A));
135+
var A2 = (function () {
136+
function A2() {
137+
}
138+
return A2;
139+
}());
140+
var B = (function (_super) {
141+
__extends(B, _super);
142+
function B() {
143+
_super.apply(this, arguments);
144+
}
145+
return B;
146+
}(A));
147+
function goo(x) {
148+
if (x instanceof A) {
149+
x; // A
150+
}
151+
else {
152+
x; // never
153+
}
154+
if (x instanceof A1) {
155+
x; // A1
156+
}
157+
else {
158+
x; // A
159+
}
160+
if (x instanceof A2) {
161+
x; // A2
162+
}
163+
else {
164+
x; // A
165+
}
166+
if (x instanceof B) {
167+
x; // B
168+
}
169+
else {
170+
x; // A
171+
}
172+
}

0 commit comments

Comments
 (0)