diff --git a/tests/baselines/reference/intersectionTypeInference.errors.txt b/tests/baselines/reference/intersectionTypeInference.errors.txt index 33c24e111dc..af0b1b447bc 100644 --- a/tests/baselines/reference/intersectionTypeInference.errors.txt +++ b/tests/baselines/reference/intersectionTypeInference.errors.txt @@ -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(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 { + a: T; + } + + interface B { + b: U; + } + + function foo(obj: A & B): T | U { + return undefined; + } + + var z = foo({ a: "hello", b: 42 }); + var z: string | number; \ No newline at end of file diff --git a/tests/baselines/reference/intersectionTypeInference.js b/tests/baselines/reference/intersectionTypeInference.js index 0b95879a6c0..8e7f1238c07 100644 --- a/tests/baselines/reference/intersectionTypeInference.js +++ b/tests/baselines/reference/intersectionTypeInference.js @@ -1,5 +1,4 @@ //// [intersectionTypeInference.ts] - function extend(obj1: T, obj2: U): T & U { var result: T & U; obj1 = result; @@ -12,6 +11,21 @@ function extend(obj1: T, obj2: U): T & U { var x = extend({ a: "hello" }, { b: 42 }); var s = x.a; var n = x.b; + +interface A { + a: T; +} + +interface B { + b: U; +} + +function foo(obj: A & B): 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; diff --git a/tests/cases/conformance/types/intersection/intersectionTypeInference.ts b/tests/cases/conformance/types/intersection/intersectionTypeInference.ts index 3126ce09448..32a419ff03a 100644 --- a/tests/cases/conformance/types/intersection/intersectionTypeInference.ts +++ b/tests/cases/conformance/types/intersection/intersectionTypeInference.ts @@ -1,4 +1,3 @@ - function extend(obj1: T, obj2: U): T & U { var result: T & U; obj1 = result; @@ -11,3 +10,18 @@ function extend(obj1: T, obj2: U): T & U { var x = extend({ a: "hello" }, { b: 42 }); var s = x.a; var n = x.b; + +interface A { + a: T; +} + +interface B { + b: U; +} + +function foo(obj: A & B): T | U { + return undefined; +} + +var z = foo({ a: "hello", b: 42 }); +var z: string | number;