Skip to content

Commit 561360d

Browse files
committed
Adding regression test
1 parent 181c10a commit 561360d

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [unionTypeParameterInference.ts]
2+
interface Foo<T> { prop: T; }
3+
4+
declare function lift<U>(value: U | Foo<U>): Foo<U>;
5+
6+
function unlift<U>(value: U | Foo<U>): U {
7+
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
8+
}
9+
10+
11+
//// [unionTypeParameterInference.js]
12+
function unlift(value) {
13+
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/unionTypeParameterInference.ts ===
2+
interface Foo<T> { prop: T; }
3+
>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0))
4+
>T : Symbol(T, Decl(unionTypeParameterInference.ts, 0, 14))
5+
>prop : Symbol(prop, Decl(unionTypeParameterInference.ts, 0, 18))
6+
>T : Symbol(T, Decl(unionTypeParameterInference.ts, 0, 14))
7+
8+
declare function lift<U>(value: U | Foo<U>): Foo<U>;
9+
>lift : Symbol(lift, Decl(unionTypeParameterInference.ts, 0, 29))
10+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22))
11+
>value : Symbol(value, Decl(unionTypeParameterInference.ts, 2, 25))
12+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22))
13+
>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0))
14+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22))
15+
>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0))
16+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 2, 22))
17+
18+
function unlift<U>(value: U | Foo<U>): U {
19+
>unlift : Symbol(unlift, Decl(unionTypeParameterInference.ts, 2, 52))
20+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16))
21+
>value : Symbol(value, Decl(unionTypeParameterInference.ts, 4, 19))
22+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16))
23+
>Foo : Symbol(Foo, Decl(unionTypeParameterInference.ts, 0, 0))
24+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16))
25+
>U : Symbol(U, Decl(unionTypeParameterInference.ts, 4, 16))
26+
27+
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
28+
>lift(value).prop : Symbol(Foo.prop, Decl(unionTypeParameterInference.ts, 0, 18))
29+
>lift : Symbol(lift, Decl(unionTypeParameterInference.ts, 0, 29))
30+
>value : Symbol(value, Decl(unionTypeParameterInference.ts, 4, 19))
31+
>prop : Symbol(Foo.prop, Decl(unionTypeParameterInference.ts, 0, 18))
32+
}
33+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/compiler/unionTypeParameterInference.ts ===
2+
interface Foo<T> { prop: T; }
3+
>Foo : Foo<T>
4+
>T : T
5+
>prop : T
6+
>T : T
7+
8+
declare function lift<U>(value: U | Foo<U>): Foo<U>;
9+
>lift : <U>(value: U | Foo<U>) => Foo<U>
10+
>U : U
11+
>value : U | Foo<U>
12+
>U : U
13+
>Foo : Foo<T>
14+
>U : U
15+
>Foo : Foo<T>
16+
>U : U
17+
18+
function unlift<U>(value: U | Foo<U>): U {
19+
>unlift : <U>(value: U | Foo<U>) => U
20+
>U : U
21+
>value : U | Foo<U>
22+
>U : U
23+
>Foo : Foo<T>
24+
>U : U
25+
>U : U
26+
27+
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
28+
>lift(value).prop : U
29+
>lift(value) : Foo<U>
30+
>lift : <U>(value: U | Foo<U>) => Foo<U>
31+
>value : U | Foo<U>
32+
>prop : U
33+
}
34+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface Foo<T> { prop: T; }
2+
3+
declare function lift<U>(value: U | Foo<U>): Foo<U>;
4+
5+
function unlift<U>(value: U | Foo<U>): U {
6+
return lift(value).prop; // error TS2322: Type '{}' is not assignable to type 'U'.
7+
}

0 commit comments

Comments
 (0)