Adding regression test

This commit is contained in:
Anders Hejlsberg
2015-12-02 10:23:49 -08:00
parent 181c10a78f
commit 561360d550
4 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
//// [unionTypeParameterInference.ts]
interface Foo<T> { prop: T; }
declare function lift<U>(value: U | Foo<U>): Foo<U>;
function unlift<U>(value: U | Foo<U>): 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'.
}

View File

@@ -0,0 +1,33 @@
=== tests/cases/compiler/unionTypeParameterInference.ts ===
interface Foo<T> { 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<U>(value: U | Foo<U>): Foo<U>;
>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<U>(value: U | Foo<U>): 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))
}

View File

@@ -0,0 +1,34 @@
=== tests/cases/compiler/unionTypeParameterInference.ts ===
interface Foo<T> { prop: T; }
>Foo : Foo<T>
>T : T
>prop : T
>T : T
declare function lift<U>(value: U | Foo<U>): Foo<U>;
>lift : <U>(value: U | Foo<U>) => Foo<U>
>U : U
>value : U | Foo<U>
>U : U
>Foo : Foo<T>
>U : U
>Foo : Foo<T>
>U : U
function unlift<U>(value: U | Foo<U>): U {
>unlift : <U>(value: U | Foo<U>) => U
>U : U
>value : U | Foo<U>
>U : U
>Foo : Foo<T>
>U : U
>U : U
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
>lift(value).prop : U
>lift(value) : Foo<U>
>lift : <U>(value: U | Foo<U>) => Foo<U>
>value : U | Foo<U>
>prop : U
}

View File

@@ -0,0 +1,7 @@
interface Foo<T> { prop: T; }
declare function lift<U>(value: U | Foo<U>): Foo<U>;
function unlift<U>(value: U | Foo<U>): U {
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
}