Skip to content

Commit fb1bf42

Browse files
committed
Adding test for inference with intersection type as target
1 parent 6ae775b commit fb1bf42

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

tests/baselines/reference/intersectionTypeInference.errors.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(6,5): error TS2322: Type 'T' is not assignable to type 'T & U'.
1+
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(5,5): error TS2322: Type 'T' is not assignable to type 'T & U'.
22
Type 'T' is not assignable to type 'U'.
3-
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): error TS2322: Type 'U' is not assignable to type 'T & U'.
3+
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(6,5): error TS2322: Type 'U' is not assignable to type 'T & U'.
44
Type 'U' is not assignable to type 'T'.
55

66

77
==== tests/cases/conformance/types/intersection/intersectionTypeInference.ts (2 errors) ====
8-
98
function extend<T, U>(obj1: T, obj2: U): T & U {
109
var result: T & U;
1110
obj1 = result;
@@ -24,4 +23,19 @@ tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): er
2423
var x = extend({ a: "hello" }, { b: 42 });
2524
var s = x.a;
2625
var n = x.b;
26+
27+
interface A<T> {
28+
a: T;
29+
}
30+
31+
interface B<U> {
32+
b: U;
33+
}
34+
35+
function foo<T, U>(obj: A<T> & B<U>): T | U {
36+
return undefined;
37+
}
38+
39+
var z = foo({ a: "hello", b: 42 });
40+
var z: string | number;
2741

tests/baselines/reference/intersectionTypeInference.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//// [intersectionTypeInference.ts]
2-
32
function extend<T, U>(obj1: T, obj2: U): T & U {
43
var result: T & U;
54
obj1 = result;
@@ -12,6 +11,21 @@ function extend<T, U>(obj1: T, obj2: U): T & U {
1211
var x = extend({ a: "hello" }, { b: 42 });
1312
var s = x.a;
1413
var n = x.b;
14+
15+
interface A<T> {
16+
a: T;
17+
}
18+
19+
interface B<U> {
20+
b: U;
21+
}
22+
23+
function foo<T, U>(obj: A<T> & B<U>): T | U {
24+
return undefined;
25+
}
26+
27+
var z = foo({ a: "hello", b: 42 });
28+
var z: string | number;
1529

1630

1731
//// [intersectionTypeInference.js]
@@ -26,3 +40,8 @@ function extend(obj1, obj2) {
2640
var x = extend({ a: "hello" }, { b: 42 });
2741
var s = x.a;
2842
var n = x.b;
43+
function foo(obj) {
44+
return undefined;
45+
}
46+
var z = foo({ a: "hello", b: 42 });
47+
var z;

tests/cases/conformance/types/intersection/intersectionTypeInference.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-

21
function extend<T, U>(obj1: T, obj2: U): T & U {
32
var result: T & U;
43
obj1 = result;
@@ -11,3 +10,18 @@ function extend<T, U>(obj1: T, obj2: U): T & U {
1110
var x = extend({ a: "hello" }, { b: 42 });
1211
var s = x.a;
1312
var n = x.b;
13+
14+
interface A<T> {
15+
a: T;
16+
}
17+
18+
interface B<U> {
19+
b: U;
20+
}
21+
22+
function foo<T, U>(obj: A<T> & B<U>): T | U {
23+
return undefined;
24+
}
25+
26+
var z = foo({ a: "hello", b: 42 });
27+
var z: string | number;

0 commit comments

Comments
 (0)