Adding test for inference with intersection type as target
This commit is contained in:
parent
6ae775b4ff
commit
fb1bf420b4
|
@ -1,11 +1,10 @@
|
|||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(6,5): error TS2322: Type 'T' is not assignable to type 'T & U'.
|
||||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(5,5): error TS2322: Type 'T' is not assignable to type 'T & U'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): error TS2322: Type 'U' is not assignable to type 'T & U'.
|
||||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(6,5): error TS2322: Type 'U' is not assignable to type 'T & U'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/intersection/intersectionTypeInference.ts (2 errors) ====
|
||||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
|
@ -25,3 +24,18 @@ tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): er
|
|||
var s = x.a;
|
||||
var n = x.b;
|
||||
|
||||
interface A<T> {
|
||||
a: T;
|
||||
}
|
||||
|
||||
interface B<U> {
|
||||
b: U;
|
||||
}
|
||||
|
||||
function foo<T, U>(obj: A<T> & B<U>): T | U {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var z = foo({ a: "hello", b: 42 });
|
||||
var z: string | number;
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
//// [intersectionTypeInference.ts]
|
||||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
|
@ -13,6 +12,21 @@ var x = extend({ a: "hello" }, { b: 42 });
|
|||
var s = x.a;
|
||||
var n = x.b;
|
||||
|
||||
interface A<T> {
|
||||
a: T;
|
||||
}
|
||||
|
||||
interface B<U> {
|
||||
b: U;
|
||||
}
|
||||
|
||||
function foo<T, U>(obj: A<T> & B<U>): T | U {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var z = foo({ a: "hello", b: 42 });
|
||||
var z: string | number;
|
||||
|
||||
|
||||
//// [intersectionTypeInference.js]
|
||||
function extend(obj1, obj2) {
|
||||
|
@ -26,3 +40,8 @@ function extend(obj1, obj2) {
|
|||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
function foo(obj) {
|
||||
return undefined;
|
||||
}
|
||||
var z = foo({ a: "hello", b: 42 });
|
||||
var z;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
|
@ -11,3 +10,18 @@ function extend<T, U>(obj1: T, obj2: U): T & U {
|
|||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
|
||||
interface A<T> {
|
||||
a: T;
|
||||
}
|
||||
|
||||
interface B<U> {
|
||||
b: U;
|
||||
}
|
||||
|
||||
function foo<T, U>(obj: A<T> & B<U>): T | U {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var z = foo({ a: "hello", b: 42 });
|
||||
var z: string | number;
|
||||
|
|
Loading…
Reference in a new issue