Skip to content

Commit a3b90b8

Browse files
committed
Add tests
1 parent 3197c17 commit a3b90b8

5 files changed

+527
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
tests/cases/compiler/intersectionWithConflictingPrivates.ts(5,4): error TS2339: Property 'y' does not exist on type 'never'.
2+
The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
3+
tests/cases/compiler/intersectionWithConflictingPrivates.ts(6,1): error TS2322: Type '{}' is not assignable to type 'never'.
4+
The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
5+
6+
7+
==== tests/cases/compiler/intersectionWithConflictingPrivates.ts (2 errors) ====
8+
class A { private x: unknown; y?: string; }
9+
class B { private x: unknown; y?: string; }
10+
11+
declare let ab: A & B;
12+
ab.y = 'hello';
13+
~
14+
!!! error TS2339: Property 'y' does not exist on type 'never'.
15+
!!! error TS2339: The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
16+
ab = {};
17+
~~
18+
!!! error TS2322: Type '{}' is not assignable to type 'never'.
19+
!!! error TS2322: The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some.
20+
21+
function f1(node: A | B) {
22+
if (node instanceof A || node instanceof A) {
23+
node; // A
24+
}
25+
else {
26+
node; // B
27+
}
28+
node; // A | B
29+
}
30+
31+
// Repro from #37659
32+
33+
abstract class ViewNode { }
34+
abstract class ViewRefNode extends ViewNode { }
35+
abstract class ViewRefFileNode extends ViewRefNode { }
36+
37+
class CommitFileNode extends ViewRefFileNode {
38+
private _id: any;
39+
}
40+
41+
class ResultsFileNode extends ViewRefFileNode {
42+
private _id: any;
43+
}
44+
45+
class StashFileNode extends CommitFileNode {
46+
private _id2: any;
47+
}
48+
49+
class StatusFileNode extends ViewNode {
50+
private _id: any;
51+
}
52+
53+
class Foo {
54+
private async foo(node: CommitFileNode | ResultsFileNode | StashFileNode) {
55+
if (
56+
!(node instanceof CommitFileNode) &&
57+
!(node instanceof StashFileNode) &&
58+
!(node instanceof ResultsFileNode)
59+
) {
60+
return;
61+
}
62+
63+
await this.bar(node);
64+
}
65+
66+
private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) {
67+
return Promise.resolve(undefined);
68+
}
69+
}
70+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//// [intersectionWithConflictingPrivates.ts]
2+
class A { private x: unknown; y?: string; }
3+
class B { private x: unknown; y?: string; }
4+
5+
declare let ab: A & B;
6+
ab.y = 'hello';
7+
ab = {};
8+
9+
function f1(node: A | B) {
10+
if (node instanceof A || node instanceof A) {
11+
node; // A
12+
}
13+
else {
14+
node; // B
15+
}
16+
node; // A | B
17+
}
18+
19+
// Repro from #37659
20+
21+
abstract class ViewNode { }
22+
abstract class ViewRefNode extends ViewNode { }
23+
abstract class ViewRefFileNode extends ViewRefNode { }
24+
25+
class CommitFileNode extends ViewRefFileNode {
26+
private _id: any;
27+
}
28+
29+
class ResultsFileNode extends ViewRefFileNode {
30+
private _id: any;
31+
}
32+
33+
class StashFileNode extends CommitFileNode {
34+
private _id2: any;
35+
}
36+
37+
class StatusFileNode extends ViewNode {
38+
private _id: any;
39+
}
40+
41+
class Foo {
42+
private async foo(node: CommitFileNode | ResultsFileNode | StashFileNode) {
43+
if (
44+
!(node instanceof CommitFileNode) &&
45+
!(node instanceof StashFileNode) &&
46+
!(node instanceof ResultsFileNode)
47+
) {
48+
return;
49+
}
50+
51+
await this.bar(node);
52+
}
53+
54+
private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) {
55+
return Promise.resolve(undefined);
56+
}
57+
}
58+
59+
60+
//// [intersectionWithConflictingPrivates.js]
61+
"use strict";
62+
class A {
63+
}
64+
class B {
65+
}
66+
ab.y = 'hello';
67+
ab = {};
68+
function f1(node) {
69+
if (node instanceof A || node instanceof A) {
70+
node; // A
71+
}
72+
else {
73+
node; // B
74+
}
75+
node; // A | B
76+
}
77+
// Repro from #37659
78+
class ViewNode {
79+
}
80+
class ViewRefNode extends ViewNode {
81+
}
82+
class ViewRefFileNode extends ViewRefNode {
83+
}
84+
class CommitFileNode extends ViewRefFileNode {
85+
}
86+
class ResultsFileNode extends ViewRefFileNode {
87+
}
88+
class StashFileNode extends CommitFileNode {
89+
}
90+
class StatusFileNode extends ViewNode {
91+
}
92+
class Foo {
93+
async foo(node) {
94+
if (!(node instanceof CommitFileNode) &&
95+
!(node instanceof StashFileNode) &&
96+
!(node instanceof ResultsFileNode)) {
97+
return;
98+
}
99+
await this.bar(node);
100+
}
101+
async bar(node, options) {
102+
return Promise.resolve(undefined);
103+
}
104+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
=== tests/cases/compiler/intersectionWithConflictingPrivates.ts ===
2+
class A { private x: unknown; y?: string; }
3+
>A : Symbol(A, Decl(intersectionWithConflictingPrivates.ts, 0, 0))
4+
>x : Symbol(A.x, Decl(intersectionWithConflictingPrivates.ts, 0, 9))
5+
>y : Symbol(A.y, Decl(intersectionWithConflictingPrivates.ts, 0, 29))
6+
7+
class B { private x: unknown; y?: string; }
8+
>B : Symbol(B, Decl(intersectionWithConflictingPrivates.ts, 0, 43))
9+
>x : Symbol(B.x, Decl(intersectionWithConflictingPrivates.ts, 1, 9))
10+
>y : Symbol(B.y, Decl(intersectionWithConflictingPrivates.ts, 1, 29))
11+
12+
declare let ab: A & B;
13+
>ab : Symbol(ab, Decl(intersectionWithConflictingPrivates.ts, 3, 11))
14+
>A : Symbol(A, Decl(intersectionWithConflictingPrivates.ts, 0, 0))
15+
>B : Symbol(B, Decl(intersectionWithConflictingPrivates.ts, 0, 43))
16+
17+
ab.y = 'hello';
18+
>ab : Symbol(ab, Decl(intersectionWithConflictingPrivates.ts, 3, 11))
19+
20+
ab = {};
21+
>ab : Symbol(ab, Decl(intersectionWithConflictingPrivates.ts, 3, 11))
22+
23+
function f1(node: A | B) {
24+
>f1 : Symbol(f1, Decl(intersectionWithConflictingPrivates.ts, 5, 8))
25+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
26+
>A : Symbol(A, Decl(intersectionWithConflictingPrivates.ts, 0, 0))
27+
>B : Symbol(B, Decl(intersectionWithConflictingPrivates.ts, 0, 43))
28+
29+
if (node instanceof A || node instanceof A) {
30+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
31+
>A : Symbol(A, Decl(intersectionWithConflictingPrivates.ts, 0, 0))
32+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
33+
>A : Symbol(A, Decl(intersectionWithConflictingPrivates.ts, 0, 0))
34+
35+
node; // A
36+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
37+
}
38+
else {
39+
node; // B
40+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
41+
}
42+
node; // A | B
43+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 7, 12))
44+
}
45+
46+
// Repro from #37659
47+
48+
abstract class ViewNode { }
49+
>ViewNode : Symbol(ViewNode, Decl(intersectionWithConflictingPrivates.ts, 15, 1))
50+
51+
abstract class ViewRefNode extends ViewNode { }
52+
>ViewRefNode : Symbol(ViewRefNode, Decl(intersectionWithConflictingPrivates.ts, 19, 27))
53+
>ViewNode : Symbol(ViewNode, Decl(intersectionWithConflictingPrivates.ts, 15, 1))
54+
55+
abstract class ViewRefFileNode extends ViewRefNode { }
56+
>ViewRefFileNode : Symbol(ViewRefFileNode, Decl(intersectionWithConflictingPrivates.ts, 20, 47))
57+
>ViewRefNode : Symbol(ViewRefNode, Decl(intersectionWithConflictingPrivates.ts, 19, 27))
58+
59+
class CommitFileNode extends ViewRefFileNode {
60+
>CommitFileNode : Symbol(CommitFileNode, Decl(intersectionWithConflictingPrivates.ts, 21, 54))
61+
>ViewRefFileNode : Symbol(ViewRefFileNode, Decl(intersectionWithConflictingPrivates.ts, 20, 47))
62+
63+
private _id: any;
64+
>_id : Symbol(CommitFileNode._id, Decl(intersectionWithConflictingPrivates.ts, 23, 46))
65+
}
66+
67+
class ResultsFileNode extends ViewRefFileNode {
68+
>ResultsFileNode : Symbol(ResultsFileNode, Decl(intersectionWithConflictingPrivates.ts, 25, 1))
69+
>ViewRefFileNode : Symbol(ViewRefFileNode, Decl(intersectionWithConflictingPrivates.ts, 20, 47))
70+
71+
private _id: any;
72+
>_id : Symbol(ResultsFileNode._id, Decl(intersectionWithConflictingPrivates.ts, 27, 47))
73+
}
74+
75+
class StashFileNode extends CommitFileNode {
76+
>StashFileNode : Symbol(StashFileNode, Decl(intersectionWithConflictingPrivates.ts, 29, 1))
77+
>CommitFileNode : Symbol(CommitFileNode, Decl(intersectionWithConflictingPrivates.ts, 21, 54))
78+
79+
private _id2: any;
80+
>_id2 : Symbol(StashFileNode._id2, Decl(intersectionWithConflictingPrivates.ts, 31, 44))
81+
}
82+
83+
class StatusFileNode extends ViewNode {
84+
>StatusFileNode : Symbol(StatusFileNode, Decl(intersectionWithConflictingPrivates.ts, 33, 1))
85+
>ViewNode : Symbol(ViewNode, Decl(intersectionWithConflictingPrivates.ts, 15, 1))
86+
87+
private _id: any;
88+
>_id : Symbol(StatusFileNode._id, Decl(intersectionWithConflictingPrivates.ts, 35, 39))
89+
}
90+
91+
class Foo {
92+
>Foo : Symbol(Foo, Decl(intersectionWithConflictingPrivates.ts, 37, 1))
93+
94+
private async foo(node: CommitFileNode | ResultsFileNode | StashFileNode) {
95+
>foo : Symbol(Foo.foo, Decl(intersectionWithConflictingPrivates.ts, 39, 11))
96+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 40, 20))
97+
>CommitFileNode : Symbol(CommitFileNode, Decl(intersectionWithConflictingPrivates.ts, 21, 54))
98+
>ResultsFileNode : Symbol(ResultsFileNode, Decl(intersectionWithConflictingPrivates.ts, 25, 1))
99+
>StashFileNode : Symbol(StashFileNode, Decl(intersectionWithConflictingPrivates.ts, 29, 1))
100+
101+
if (
102+
!(node instanceof CommitFileNode) &&
103+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 40, 20))
104+
>CommitFileNode : Symbol(CommitFileNode, Decl(intersectionWithConflictingPrivates.ts, 21, 54))
105+
106+
!(node instanceof StashFileNode) &&
107+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 40, 20))
108+
>StashFileNode : Symbol(StashFileNode, Decl(intersectionWithConflictingPrivates.ts, 29, 1))
109+
110+
!(node instanceof ResultsFileNode)
111+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 40, 20))
112+
>ResultsFileNode : Symbol(ResultsFileNode, Decl(intersectionWithConflictingPrivates.ts, 25, 1))
113+
114+
) {
115+
return;
116+
}
117+
118+
await this.bar(node);
119+
>this.bar : Symbol(Foo.bar, Decl(intersectionWithConflictingPrivates.ts, 50, 2))
120+
>this : Symbol(Foo, Decl(intersectionWithConflictingPrivates.ts, 37, 1))
121+
>bar : Symbol(Foo.bar, Decl(intersectionWithConflictingPrivates.ts, 50, 2))
122+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 40, 20))
123+
}
124+
125+
private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) {
126+
>bar : Symbol(Foo.bar, Decl(intersectionWithConflictingPrivates.ts, 50, 2))
127+
>node : Symbol(node, Decl(intersectionWithConflictingPrivates.ts, 52, 20))
128+
>CommitFileNode : Symbol(CommitFileNode, Decl(intersectionWithConflictingPrivates.ts, 21, 54))
129+
>ResultsFileNode : Symbol(ResultsFileNode, Decl(intersectionWithConflictingPrivates.ts, 25, 1))
130+
>StashFileNode : Symbol(StashFileNode, Decl(intersectionWithConflictingPrivates.ts, 29, 1))
131+
>StatusFileNode : Symbol(StatusFileNode, Decl(intersectionWithConflictingPrivates.ts, 33, 1))
132+
>options : Symbol(options, Decl(intersectionWithConflictingPrivates.ts, 52, 92))
133+
134+
return Promise.resolve(undefined);
135+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
136+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
137+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
138+
>undefined : Symbol(undefined)
139+
}
140+
}
141+

0 commit comments

Comments
 (0)