From 561360d550de590129fd899452c15d2e5d081d9d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 2 Dec 2015 10:23:49 -0800 Subject: [PATCH] Adding regression test --- .../reference/unionTypeParameterInference.js | 14 ++++++++ .../unionTypeParameterInference.symbols | 33 ++++++++++++++++++ .../unionTypeParameterInference.types | 34 +++++++++++++++++++ .../compiler/unionTypeParameterInference.ts | 7 ++++ 4 files changed, 88 insertions(+) create mode 100644 tests/baselines/reference/unionTypeParameterInference.js create mode 100644 tests/baselines/reference/unionTypeParameterInference.symbols create mode 100644 tests/baselines/reference/unionTypeParameterInference.types create mode 100644 tests/cases/compiler/unionTypeParameterInference.ts diff --git a/tests/baselines/reference/unionTypeParameterInference.js b/tests/baselines/reference/unionTypeParameterInference.js new file mode 100644 index 00000000000..cc797c511c8 --- /dev/null +++ b/tests/baselines/reference/unionTypeParameterInference.js @@ -0,0 +1,14 @@ +//// [unionTypeParameterInference.ts] +interface Foo { prop: T; } + +declare function lift(value: U | Foo): Foo; + +function unlift(value: U | Foo): U { + return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'. +} + + +//// [unionTypeParameterInference.js] +function unlift(value) { + return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'. +} diff --git a/tests/baselines/reference/unionTypeParameterInference.symbols b/tests/baselines/reference/unionTypeParameterInference.symbols new file mode 100644 index 00000000000..ee540379284 --- /dev/null +++ b/tests/baselines/reference/unionTypeParameterInference.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/unionTypeParameterInference.ts === +interface Foo { prop: T; } +>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0)) +>T : Symbol(T, Decl(unionTypeParameterInference.ts, 0, 14)) +>prop : Symbol(prop, Decl(unionTypeParameterInference.ts, 0, 18)) +>T : Symbol(T, Decl(unionTypeParameterInference.ts, 0, 14)) + +declare function lift(value: U | Foo): Foo; +>lift : Symbol(lift, Decl(unionTypeParameterInference.ts, 0, 29)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22)) +>value : Symbol(value, Decl(unionTypeParameterInference.ts, 2, 25)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22)) +>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22)) +>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22)) + +function unlift(value: U | Foo): U { +>unlift : Symbol(unlift, Decl(unionTypeParameterInference.ts, 2, 52)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16)) +>value : Symbol(value, Decl(unionTypeParameterInference.ts, 4, 19)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16)) +>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16)) +>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16)) + + return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'. +>lift(value).prop : Symbol(Foo.prop, Decl(unionTypeParameterInference.ts, 0, 18)) +>lift : Symbol(lift, Decl(unionTypeParameterInference.ts, 0, 29)) +>value : Symbol(value, Decl(unionTypeParameterInference.ts, 4, 19)) +>prop : Symbol(Foo.prop, Decl(unionTypeParameterInference.ts, 0, 18)) +} + diff --git a/tests/baselines/reference/unionTypeParameterInference.types b/tests/baselines/reference/unionTypeParameterInference.types new file mode 100644 index 00000000000..a4b6a09cf2c --- /dev/null +++ b/tests/baselines/reference/unionTypeParameterInference.types @@ -0,0 +1,34 @@ +=== tests/cases/compiler/unionTypeParameterInference.ts === +interface Foo { prop: T; } +>Foo : Foo +>T : T +>prop : T +>T : T + +declare function lift(value: U | Foo): Foo; +>lift : (value: U | Foo) => Foo +>U : U +>value : U | Foo +>U : U +>Foo : Foo +>U : U +>Foo : Foo +>U : U + +function unlift(value: U | Foo): U { +>unlift : (value: U | Foo) => U +>U : U +>value : U | Foo +>U : U +>Foo : Foo +>U : U +>U : U + + return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'. +>lift(value).prop : U +>lift(value) : Foo +>lift : (value: U | Foo) => Foo +>value : U | Foo +>prop : U +} + diff --git a/tests/cases/compiler/unionTypeParameterInference.ts b/tests/cases/compiler/unionTypeParameterInference.ts new file mode 100644 index 00000000000..221b0891b98 --- /dev/null +++ b/tests/cases/compiler/unionTypeParameterInference.ts @@ -0,0 +1,7 @@ +interface Foo { prop: T; } + +declare function lift(value: U | Foo): Foo; + +function unlift(value: U | Foo): U { + return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'. +}