Skip to content

Commit 7c0cc84

Browse files
committed
Add tests
1 parent 8750bb8 commit 7c0cc84

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
interface Covariant<T> {
5+
foo: T extends string ? T : number;
6+
}
7+
8+
interface Contravariant<T> {
9+
foo: T extends string ? keyof T : number;
10+
}
11+
12+
interface Invariant<T> {
13+
foo: T extends string ? keyof T : T;
14+
}
15+
16+
interface A { a: string }
17+
interface B extends A { b: string }
18+
19+
20+
function f1(a: Covariant<A>, b: Covariant<B>) {
21+
a = b;
22+
b = a; // Error
23+
}
24+
25+
function f2(a: Contravariant<A>, b: Contravariant<B>) {
26+
a = b; // Error
27+
b = a;
28+
}
29+
30+
function f3(a: Invariant<A>, b: Invariant<B>) {
31+
a = b; // Error
32+
b = a; // Error
33+
}
34+
35+
// Repros from #22860
36+
37+
export class Option<T> {
38+
toVector(): Vector<T> {
39+
return <any>undefined;
40+
}
41+
}
42+
43+
interface Seq<T> {
44+
tail(): Option<Seq<T>>;
45+
}
46+
47+
class Vector<T> implements Seq<T> {
48+
tail(): Option<Vector<T>> {
49+
return <any>undefined;
50+
}
51+
partition2<U extends T>(predicate:(v:T)=>v is U): [Vector<U>,Vector<Exclude<T, U>>];
52+
partition2(predicate:(x:T)=>boolean): [Vector<T>,Vector<T>];
53+
partition2<U extends T>(predicate:(v:T)=>boolean): [Vector<U>,Vector<any>] {
54+
return <any>undefined;
55+
}
56+
}
57+
58+
interface A1<T> {
59+
bat: B1<A1<T>>;
60+
}
61+
62+
interface B1<T> extends A1<T> {
63+
bat: B1<B1<T>>;
64+
boom: T extends any ? true : true
65+
}

0 commit comments

Comments
 (0)