File: constructSignatureAssignabilityInInheritance3.errors.txt

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (194 lines) | stat: -rw-r--r-- 11,669 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(41,19): error TS2430: Interface 'I2<T, U>' incorrectly extends interface 'A'.
  Types of property 'a2' are incompatible.
    Type 'new (x: T) => U[]' is not assignable to type 'new (x: number) => string[]'.
      Types of parameters 'x' and 'x' are incompatible.
        Type 'number' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(50,19): error TS2430: Interface 'I4' incorrectly extends interface 'A'.
  Types of property 'a8' are incompatible.
    Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'.
      Types of parameters 'y' and 'y' are incompatible.
        Types of parameters 'arg2' and 'arg2' are incompatible.
          Type '{ foo: number; }' is not assignable to type 'Base'.
            Types of property 'foo' are incompatible.
              Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(66,19): error TS2430: Interface 'I6' incorrectly extends interface 'A'.
  Types of property 'a15' are incompatible.
    Type 'new <T>(x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'.
      Types of parameters 'x' and 'x' are incompatible.
        Type '{ a: string; b: number; }' is not assignable to type '{ a: string; b: string; }'.
          Types of property 'b' are incompatible.
            Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(70,19): error TS2430: Interface 'I7' incorrectly extends interface 'A'.
  Types of property 'a15' are incompatible.
    Type 'new <T extends Base>(x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'.
      Types of parameters 'x' and 'x' are incompatible.
        Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'.
          Types of property 'a' are incompatible.
            Type 'string' is not assignable to type 'Base'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(86,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'.
  Types of property 'a2' are incompatible.
    Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
      Type 'string[]' is not assignable to type 'T[]'.
        Type 'string' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(95,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'.
  Types of property 'a2' are incompatible.
    Type 'new <T>(x: T) => T[]' is not assignable to type 'new <T>(x: T) => string[]'.
      Type 'T[]' is not assignable to type 'string[]'.
        Type 'T' is not assignable to type 'string'.


==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (6 errors) ====
    // checking subtype relations for function types as it relates to contextual signature instantiation
    // error cases
    
    module Errors {
        class Base { foo: string; }
        class Derived extends Base { bar: string; }
        class Derived2 extends Derived { baz: string; }
        class OtherDerived extends Base { bing: string; }
    
        module WithNonGenericSignaturesInBaseType {
            // base type with non-generic call signatures
            interface A {
                a2: new (x: number) => string[];
                a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived2;
                a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived;
                a10: new (...x: Base[]) => Base;
                a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base;
                a12: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
                a14: {
                    new (x: number): number[];
                    new (x: string): string[];
                };
                a15: new (x: { a: string; b: number }) => number;
                a16: {
                    // type of parameter is overload set which means we can't do inference based on this type
                    new (x: {
                        new (a: number): number;
                        new (a?: number): number;
                    }): number[];
                    new (x: {
                        new (a: boolean): boolean;
                        new (a?: boolean): boolean;
                    }): boolean[];
                };
            }
    
            interface I extends A {
                a2: new <T, U>(x: T) => U[]; // error, contextual signature instantiation doesn't relate return types so U is {}, not a subtype of string[]
            }
    
            interface I2<T, U> extends A {
                      ~~
!!! error TS2430: Interface 'I2<T, U>' incorrectly extends interface 'A'.
!!! error TS2430:   Types of property 'a2' are incompatible.
!!! error TS2430:     Type 'new (x: T) => U[]' is not assignable to type 'new (x: number) => string[]'.
!!! error TS2430:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2430:         Type 'number' is not assignable to type 'T'.
                a2: new (x: T) => U[]; // error, no contextual signature instantiation since I2.a2 is not generic
            }
    
            interface I3 extends A {
                // valid, no inferences for V so it defaults to Derived2
                a7: new <T extends Base, U extends Derived, V extends Derived2>(x: (arg: T) => U) => (r: T) => V;
            }
    
            interface I4 extends A {
                      ~~
!!! error TS2430: Interface 'I4' incorrectly extends interface 'A'.
!!! error TS2430:   Types of property 'a8' are incompatible.
!!! error TS2430:     Type 'new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'.
!!! error TS2430:       Types of parameters 'y' and 'y' are incompatible.
!!! error TS2430:         Types of parameters 'arg2' and 'arg2' are incompatible.
!!! error TS2430:           Type '{ foo: number; }' is not assignable to type 'Base'.
!!! error TS2430:             Types of property 'foo' are incompatible.
!!! error TS2430:               Type 'number' is not assignable to type 'string'.
                a8: new <T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch
            }
    
            interface I4B extends A {
                a10: new <T extends Derived>(...x: T[]) => T; // valid, parameter covariance works even after contextual signature instantiation
            }
    
            interface I4C extends A {
                a11: new <T extends Derived>(x: T, y: T) => T; // valid, even though x is a Base, parameter covariance works even after contextual signature instantiation
            }
    
            interface I4E extends A {
                a12: new <T extends Array<Derived2>>(x: Array<Base>, y: Array<Base>) => T; // valid, no inferences for T, defaults to Array<Derived2>
            }
    
            interface I6 extends A {
                      ~~
!!! error TS2430: Interface 'I6' incorrectly extends interface 'A'.
!!! error TS2430:   Types of property 'a15' are incompatible.
!!! error TS2430:     Type 'new <T>(x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'.
!!! error TS2430:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2430:         Type '{ a: string; b: number; }' is not assignable to type '{ a: string; b: string; }'.
!!! error TS2430:           Types of property 'b' are incompatible.
!!! error TS2430:             Type 'number' is not assignable to type 'string'.
                a15: new <T>(x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type
            }
    
            interface I7 extends A {
                      ~~
!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'.
!!! error TS2430:   Types of property 'a15' are incompatible.
!!! error TS2430:     Type 'new <T extends Base>(x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'.
!!! error TS2430:       Types of parameters 'x' and 'x' are incompatible.
!!! error TS2430:         Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'.
!!! error TS2430:           Types of property 'a' are incompatible.
!!! error TS2430:             Type 'string' is not assignable to type 'Base'.
                a15: new <T extends Base>(x: { a: T; b: T }) => number; // error, T defaults to Base, which is not compatible with number or string
            }
    
            interface I8 extends A {
                // ok, we relate each signature of a16 to b16, and within that, we make inferences from two different signatures in the respective A.a16 signature
                a16: new <T>(x: new (a: T) => T) => T[];
            }
        }
    
        module WithGenericSignaturesInBaseType {
            // base type has generic call signature
            interface B {
                a2: new <T>(x: T) => T[];
            }
    
            interface I6 extends B {
                      ~~
!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'.
!!! error TS2430:   Types of property 'a2' are incompatible.
!!! error TS2430:     Type 'new <T>(x: T) => string[]' is not assignable to type 'new <T>(x: T) => T[]'.
!!! error TS2430:       Type 'string[]' is not assignable to type 'T[]'.
!!! error TS2430:         Type 'string' is not assignable to type 'T'.
                a2: new <T>(x: T) => string[]; // error
            }
    
            // base type has generic call signature
            interface C {
                a2: new <T>(x: T) => string[];
            }
    
            interface I7 extends C {
                      ~~
!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'.
!!! error TS2430:   Types of property 'a2' are incompatible.
!!! error TS2430:     Type 'new <T>(x: T) => T[]' is not assignable to type 'new <T>(x: T) => string[]'.
!!! error TS2430:       Type 'T[]' is not assignable to type 'string[]'.
!!! error TS2430:         Type 'T' is not assignable to type 'string'.
                a2: new <T>(x: T) => T[]; // error
            }
    
            // base type has a generic call signature with overloads
            interface D {
                a14: {
                    new <T extends Derived>(x: T): number[];
                    new <U extends Base>(x: U): number[];
                };
            }
    
            interface I8 extends D {
                a14: new <T extends Base>(x: T) => number[];
            }
        }
    }