Adding test for inference with intersection type as target

This commit is contained in:
Anders Hejlsberg 2015-06-30 12:41:03 -07:00
parent 6ae775b4ff
commit fb1bf420b4
3 changed files with 52 additions and 5 deletions

View file

@ -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;
@ -24,4 +23,19 @@ tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): er
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;

View file

@ -1,5 +1,4 @@
//// [intersectionTypeInference.ts]
function extend<T, U>(obj1: T, obj2: U): T & U {
var result: T & U;
obj1 = result;
@ -12,6 +11,21 @@ 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;
//// [intersectionTypeInference.js]
@ -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;

View file

@ -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;