File: varianceMeasurement.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (140 lines) | stat: -rw-r--r-- 6,352 bytes parent folder | download | duplicates (4)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
tests/cases/compiler/varianceMeasurement.ts(10,7): error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<"a">'.
  Type 'string' is not assignable to type '"a"'.
tests/cases/compiler/varianceMeasurement.ts(21,7): error TS2322: Type 'Foo2<string>' is not assignable to type 'Foo2<"a">'.
  Types of property 'x' are incompatible.
    Type 'string' is not assignable to type '"a"'.
tests/cases/compiler/varianceMeasurement.ts(22,7): error TS2322: Type 'Foo2<string>' is not assignable to type 'Foo2<unknown>'.
  The types of 'y.x' are incompatible between these types.
    Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
      Types of parameters 'arg' and 'arg' are incompatible.
        Type 'unknown' is not assignable to type 'string'.
tests/cases/compiler/varianceMeasurement.ts(33,7): error TS2322: Type 'Foo3<string>' is not assignable to type 'Foo3<"a">'.
  Type 'string' is not assignable to type '"a"'.
tests/cases/compiler/varianceMeasurement.ts(44,7): error TS2322: Type 'Foo4<string>' is not assignable to type 'Foo4<"a">'.
  Types of property 'x' are incompatible.
    Type 'string' is not assignable to type '"a"'.
tests/cases/compiler/varianceMeasurement.ts(45,7): error TS2322: Type 'Foo4<string>' is not assignable to type 'Foo4<unknown>'.
  The types of 'y.x' are incompatible between these types.
    Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
      Types of parameters 'arg' and 'arg' are incompatible.
        Type 'unknown' is not assignable to type 'string'.
tests/cases/compiler/varianceMeasurement.ts(57,7): error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<unknown, number>'.
  Type 'unknown' is not assignable to type 'string'.
tests/cases/compiler/varianceMeasurement.ts(62,7): error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<string, 0>'.
  Type 'number' is not assignable to type '0'.
tests/cases/compiler/varianceMeasurement.ts(75,7): error TS2322: Type 'C<unknown, number>' is not assignable to type 'C<unknown, string>'.
  Type 'number' is not assignable to type 'string'.


==== tests/cases/compiler/varianceMeasurement.ts (9 errors) ====
    // The type below should be invariant in T but is measured as covariant because
    // we don't analyze recursive references.
    
    interface Foo1<T> {
      x: T;
      y: Foo1<(arg: T) => void>;
    }
    
    declare const f10: Foo1<string>;
    const f11: Foo1<'a'> = f10;
          ~~~
!!! error TS2322: Type 'Foo1<string>' is not assignable to type 'Foo1<"a">'.
!!! error TS2322:   Type 'string' is not assignable to type '"a"'.
    const f12: Foo1<unknown> = f10;
    
    // The type below is invariant in T and is measured as such.
    
    interface Foo2<T> {
      x: T;
      y: { x: (arg: T) => void, y: Foo2<(arg: T) => void>; }
    }
    
    declare const f20: Foo2<string>;
    const f21: Foo2<'a'> = f20;
          ~~~
!!! error TS2322: Type 'Foo2<string>' is not assignable to type 'Foo2<"a">'.
!!! error TS2322:   Types of property 'x' are incompatible.
!!! error TS2322:     Type 'string' is not assignable to type '"a"'.
    const f22: Foo2<unknown> = f20;
          ~~~
!!! error TS2322: Type 'Foo2<string>' is not assignable to type 'Foo2<unknown>'.
!!! error TS2322:   The types of 'y.x' are incompatible between these types.
!!! error TS2322:     Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
!!! error TS2322:       Types of parameters 'arg' and 'arg' are incompatible.
!!! error TS2322:         Type 'unknown' is not assignable to type 'string'.
    
    // The type below should be invariant in T but is measured as covariant because
    // we don't analyze recursive references.
    
    type Foo3<T> = {
      x: T;
      y: Foo3<(arg: T) => void>;
    }
    
    declare const f30: Foo3<string>;
    const f31: Foo3<'a'> = f30;
          ~~~
!!! error TS2322: Type 'Foo3<string>' is not assignable to type 'Foo3<"a">'.
!!! error TS2322:   Type 'string' is not assignable to type '"a"'.
    const f32: Foo3<unknown> = f30;
    
    // The type below is invariant in T and is measured as such.
    
    type Foo4<T> = {
      x: T;
      y: { x: (arg: T) => void, y: Foo4<(arg: T) => void>; }
    }
    
    declare const f40: Foo4<string>;
    const f41: Foo4<'a'> = f40;
          ~~~
!!! error TS2322: Type 'Foo4<string>' is not assignable to type 'Foo4<"a">'.
!!! error TS2322:   Types of property 'x' are incompatible.
!!! error TS2322:     Type 'string' is not assignable to type '"a"'.
    const f42: Foo4<unknown> = f40;
          ~~~
!!! error TS2322: Type 'Foo4<string>' is not assignable to type 'Foo4<unknown>'.
!!! error TS2322:   The types of 'y.x' are incompatible between these types.
!!! error TS2322:     Type '(arg: string) => void' is not assignable to type '(arg: unknown) => void'.
!!! error TS2322:       Types of parameters 'arg' and 'arg' are incompatible.
!!! error TS2322:         Type 'unknown' is not assignable to type 'string'.
    
    // Repro from #3580
    
    interface Fn<A, B> {
      (a: A): B;
      then<C>(next: Fn<B, C>): Fn<A, C>;
    }
    
    declare const fn: Fn<string, number>;
    
    // Contravariant in A
    const fn1: Fn<unknown, number> = fn;  // Error
          ~~~
!!! error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<unknown, number>'.
!!! error TS2322:   Type 'unknown' is not assignable to type 'string'.
    const fn2: Fn<'a', number> = fn;
    
    // Covariant in B
    const fn3: Fn<string, unknown> = fn;
    const fn4: Fn<string, 0> = fn;  // Error
          ~~~
!!! error TS2322: Type 'Fn<string, number>' is not assignable to type 'Fn<string, 0>'.
!!! error TS2322:   Type 'number' is not assignable to type '0'.
    
    // Repro from #39947
    
    interface I<Dummy, V> {
      c: C<Dummy, V>;
    }
    
    class C<Dummy, V> {
      declare sub: I<Dummy, V>;
      declare covariance: V;
    }
    
    const c1: C<unknown, string> = new C<unknown, number>();  // Error
          ~~
!!! error TS2322: Type 'C<unknown, number>' is not assignable to type 'C<unknown, string>'.
!!! error TS2322:   Type 'number' is not assignable to type 'string'.