/
output.js
78 lines (71 loc) 路 1.62 KB
/
output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// valid JSX
<in T>() => {}</in>;
type Covariant<out T> = {
x: T;
};
declare let super_covariant: Covariant<unknown>;
declare let sub_covariant: Covariant<string>;
super_covariant = sub_covariant;
sub_covariant = super_covariant; // Error
type Contravariant<in T> = {
f: (x: T) => void;
};
declare let super_contravariant: Contravariant<unknown>;
declare let sub_contravariant: Contravariant<string>;
super_contravariant = sub_contravariant; // Error
sub_contravariant = super_contravariant;
type Invariant<in out T> = {
f: (x: T) => T;
};
declare let super_invariant: Invariant<unknown>;
declare let sub_invariant: Invariant<string>;
super_invariant = sub_invariant; // Error
sub_invariant = super_invariant; // Error
// Variance of various type constructors
type T10<out T> = T;
type T11<in T> = keyof T;
type T12<out T, out K extends keyof T> = T[K];
type T13<in out T> = T[keyof T]; // Variance annotation errors
type Covariant1<in T> = {
// Error
x: T;
};
type Contravariant1<out T> = keyof T; // Error
type Contravariant2<out T> = {
// Error
f: (x: T) => void;
};
type Invariant1<in T> = {
// Error
f: (x: T) => T;
};
type Invariant2<out T> = {
// Error
f: (x: T) => T;
}; // Variance in circular types
type Foo1<in T> = {
// Error
x: T;
f: FooFn1<T>;
};
type FooFn1<T> = (foo: Bar1<T[]>) => void;
type Bar1<T> = {
value: Foo1<T[]>;
};
type Foo2<out T> = {
// Error
x: T;
f: FooFn2<T>;
};
type FooFn2<T> = (foo: Bar2<T[]>) => void;
type Bar2<T> = {
value: Foo2<T[]>;
};
type Foo3<in out T> = {
x: T;
f: FooFn3<T>;
};
type FooFn3<T> = (foo: Bar3<T[]>) => void;
type Bar3<T> = {
value: Foo3<T[]>;
};