Skip to content

Commit 9cf958b

Browse files
committed
Add test
1 parent 3bf5323 commit 9cf958b

5 files changed

+254
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
tests/cases/compiler/intersectionReductionInFunctionReturnType.ts(15,5): error TS2322: Type 'undefined[]' is not assignable to type 'never[]'.
2+
Type 'undefined' is not assignable to type 'never'.
3+
The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
4+
tests/cases/compiler/intersectionReductionInFunctionReturnType.ts(23,3): error TS2322: Type 'undefined' is not assignable to type 'never'.
5+
tests/cases/compiler/intersectionReductionInFunctionReturnType.ts(27,3): error TS2322: Type 'undefined' is not assignable to type 'never'.
6+
The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
7+
tests/cases/compiler/intersectionReductionInFunctionReturnType.ts(30,16): error TS2534: A function returning 'never' cannot have a reachable end point.
8+
tests/cases/compiler/intersectionReductionInFunctionReturnType.ts(32,16): error TS2534: A function returning 'never' cannot have a reachable end point.
9+
The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
10+
11+
12+
==== tests/cases/compiler/intersectionReductionInFunctionReturnType.ts (5 errors) ====
13+
// repro from #46032
14+
15+
interface A {
16+
p: "a";
17+
}
18+
19+
interface B {
20+
p: "b";
21+
}
22+
23+
type C = A & B;
24+
25+
function func(): { value: C[] } {
26+
return {
27+
value: [],
28+
~~~~~
29+
!!! error TS2322: Type 'undefined[]' is not assignable to type 'never[]'.
30+
!!! error TS2322: Type 'undefined' is not assignable to type 'never'.
31+
!!! error TS2322: The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
32+
!!! related TS6500 tests/cases/compiler/intersectionReductionInFunctionReturnType.ts:13:20: The expected type comes from property 'value' which is declared here on type '{ value: never[]; }'
33+
};
34+
}
35+
36+
// other tests
37+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
38+
39+
function f1(): never {
40+
return;
41+
~~~~~~~
42+
!!! error TS2322: Type 'undefined' is not assignable to type 'never'.
43+
}
44+
45+
function f2(): C {
46+
return;
47+
~~~~~~~
48+
!!! error TS2322: Type 'undefined' is not assignable to type 'never'.
49+
!!! error TS2322: The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
50+
}
51+
52+
function g1(): never {}
53+
~~~~~
54+
!!! error TS2534: A function returning 'never' cannot have a reachable end point.
55+
56+
function g2(): C {}
57+
~
58+
!!! error TS2534: A function returning 'never' cannot have a reachable end point.
59+
!!! error TS2534: The intersection 'C' was reduced to 'never' because property 'p' has conflicting types in some constituents.
60+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [intersectionReductionInFunctionReturnType.ts]
2+
// repro from #46032
3+
4+
interface A {
5+
p: "a";
6+
}
7+
8+
interface B {
9+
p: "b";
10+
}
11+
12+
type C = A & B;
13+
14+
function func(): { value: C[] } {
15+
return {
16+
value: [],
17+
};
18+
}
19+
20+
// other tests
21+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
22+
23+
function f1(): never {
24+
return;
25+
}
26+
27+
function f2(): C {
28+
return;
29+
}
30+
31+
function g1(): never {}
32+
33+
function g2(): C {}
34+
35+
36+
//// [intersectionReductionInFunctionReturnType.js]
37+
// repro from #46032
38+
function func() {
39+
return {
40+
value: []
41+
};
42+
}
43+
// other tests
44+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
45+
function f1() {
46+
return;
47+
}
48+
function f2() {
49+
return;
50+
}
51+
function g1() { }
52+
function g2() { }
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
=== tests/cases/compiler/intersectionReductionInFunctionReturnType.ts ===
2+
// repro from #46032
3+
4+
interface A {
5+
>A : Symbol(A, Decl(intersectionReductionInFunctionReturnType.ts, 0, 0))
6+
7+
p: "a";
8+
>p : Symbol(A.p, Decl(intersectionReductionInFunctionReturnType.ts, 2, 13))
9+
}
10+
11+
interface B {
12+
>B : Symbol(B, Decl(intersectionReductionInFunctionReturnType.ts, 4, 1))
13+
14+
p: "b";
15+
>p : Symbol(B.p, Decl(intersectionReductionInFunctionReturnType.ts, 6, 13))
16+
}
17+
18+
type C = A & B;
19+
>C : Symbol(C, Decl(intersectionReductionInFunctionReturnType.ts, 8, 1))
20+
>A : Symbol(A, Decl(intersectionReductionInFunctionReturnType.ts, 0, 0))
21+
>B : Symbol(B, Decl(intersectionReductionInFunctionReturnType.ts, 4, 1))
22+
23+
function func(): { value: C[] } {
24+
>func : Symbol(func, Decl(intersectionReductionInFunctionReturnType.ts, 10, 15))
25+
>value : Symbol(value, Decl(intersectionReductionInFunctionReturnType.ts, 12, 18))
26+
>C : Symbol(C, Decl(intersectionReductionInFunctionReturnType.ts, 8, 1))
27+
28+
return {
29+
value: [],
30+
>value : Symbol(value, Decl(intersectionReductionInFunctionReturnType.ts, 13, 10))
31+
32+
};
33+
}
34+
35+
// other tests
36+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
37+
38+
function f1(): never {
39+
>f1 : Symbol(f1, Decl(intersectionReductionInFunctionReturnType.ts, 16, 1))
40+
41+
return;
42+
}
43+
44+
function f2(): C {
45+
>f2 : Symbol(f2, Decl(intersectionReductionInFunctionReturnType.ts, 23, 1))
46+
>C : Symbol(C, Decl(intersectionReductionInFunctionReturnType.ts, 8, 1))
47+
48+
return;
49+
}
50+
51+
function g1(): never {}
52+
>g1 : Symbol(g1, Decl(intersectionReductionInFunctionReturnType.ts, 27, 1))
53+
54+
function g2(): C {}
55+
>g2 : Symbol(g2, Decl(intersectionReductionInFunctionReturnType.ts, 29, 23))
56+
>C : Symbol(C, Decl(intersectionReductionInFunctionReturnType.ts, 8, 1))
57+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
=== tests/cases/compiler/intersectionReductionInFunctionReturnType.ts ===
2+
// repro from #46032
3+
4+
interface A {
5+
p: "a";
6+
>p : "a"
7+
}
8+
9+
interface B {
10+
p: "b";
11+
>p : "b"
12+
}
13+
14+
type C = A & B;
15+
>C : never
16+
17+
function func(): { value: C[] } {
18+
>func : () => { value: C[];}
19+
>value : never[]
20+
21+
return {
22+
>{ value: [], } : { value: undefined[]; }
23+
24+
value: [],
25+
>value : undefined[]
26+
>[] : undefined[]
27+
28+
};
29+
}
30+
31+
// other tests
32+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
33+
34+
function f1(): never {
35+
>f1 : () => never
36+
37+
return;
38+
}
39+
40+
function f2(): C {
41+
>f2 : () => C
42+
43+
return;
44+
}
45+
46+
function g1(): never {}
47+
>g1 : () => never
48+
49+
function g2(): C {}
50+
>g2 : () => C
51+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @strict: false
2+
3+
// repro from #46032
4+
5+
interface A {
6+
p: "a";
7+
}
8+
9+
interface B {
10+
p: "b";
11+
}
12+
13+
type C = A & B;
14+
15+
function func(): { value: C[] } {
16+
return {
17+
value: [],
18+
};
19+
}
20+
21+
// other tests
22+
// Using `C` in place of `never` shouldn't change the errors other than elaboration
23+
24+
function f1(): never {
25+
return;
26+
}
27+
28+
function f2(): C {
29+
return;
30+
}
31+
32+
function g1(): never {}
33+
34+
function g2(): C {}

0 commit comments

Comments
 (0)