You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added custom error message when trying to assign constraint type to generic type parameter (#30394)
* Added custom error message when trying to assign constraint type to generic type parameter
Fixes#29049.
This also adds the new message in chained error messages. `typeParameterDiamond4.errors.txt` shows it appearing twice in the "diamond" scenario. I can't tell if this severely increased amount of nested messages is good or bad...?
* Updated diagnostic message per suggestion
* Align formatting with local custom
Types of parameters 'arg' and 'arg' are incompatible.
16
16
Type 'string' is not assignable to type 'T'.
17
+
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
17
18
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(62,1): error TS2322: Type '(x: (arg: Base) => Derived) => Base' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U) => T'.
18
19
Types of parameters 'x' and 'x' are incompatible.
19
20
Types of parameters 'arg' and 'arg' are incompatible.
20
21
Type 'Base' is not assignable to type 'T'.
22
+
'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
21
23
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(65,1): error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U) => (r: T) => U'.
22
24
Types of parameters 'x' and 'x' are incompatible.
23
25
Types of parameters 'arg' and 'arg' are incompatible.
24
26
Type 'Base' is not assignable to type 'T'.
27
+
'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
25
28
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(68,1): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U'.
26
29
Types of parameters 'x' and 'x' are incompatible.
27
30
Types of parameters 'arg' and 'arg' are incompatible.
28
31
Type 'Base' is not assignable to type 'T'.
32
+
'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
29
33
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(71,1): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '<T extends Base, U extends Derived>(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'.
30
34
Types of parameters 'x' and 'x' are incompatible.
31
35
Types of parameters 'arg' and 'arg' are incompatible.
32
36
Type 'Base' is not assignable to type 'T'.
37
+
'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
33
38
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(74,1): error TS2322: Type '(...x: Derived[]) => Derived' is not assignable to type '<T extends Derived>(...x: T[]) => T'.
34
39
Type 'Derived' is not assignable to type 'T'.
40
+
'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'.
35
41
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(77,1): error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '<T extends Base>(x: T, y: T) => T'.
36
42
Types of parameters 'y' and 'y' are incompatible.
37
43
Type 'T' is not assignable to type '{ foo: string; bar: string; }'.
Type 'Base' is missing the following properties from type 'Derived2': baz, bar
44
50
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(83,1): error TS2322: Type '(x: Base[], y: Derived[]) => Derived[]' is not assignable to type '<T extends Derived[]>(x: Base[], y: T) => T'.
45
51
Type 'Derived[]' is not assignable to type 'T'.
52
+
'Derived[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived[]'.
46
53
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(85,1): error TS2322: Type '<T>(x: { a: T; b: T; }) => T' is not assignable to type '(x: { a: string; b: number; }) => Object'.
47
54
Types of parameters 'x' and 'x' are incompatible.
48
55
Type '{ a: string; b: number; }' is not assignable to type '{ a: string; b: string; }'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
169
180
!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible.
170
181
!!! error TS2322: Type 'Base' is not assignable to type 'T'.
182
+
!!! error TS2322: 'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
171
183
var b10: <T extends Derived>(...x: T[]) => T;
172
184
a10 = b10; // ok
173
185
b10 = a10; // ok
174
186
~~~
175
187
!!! error TS2322: Type '(...x: Derived[]) => Derived' is not assignable to type '<T extends Derived>(...x: T[]) => T'.
176
188
!!! error TS2322: Type 'Derived' is not assignable to type 'T'.
189
+
!!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'.
!!! error TS2322: Type '(x: Base[], y: Derived[]) => Derived[]' is not assignable to type '<T extends Derived[]>(x: Base[], y: T) => T'.
200
213
!!! error TS2322: Type 'Derived[]' is not assignable to type 'T'.
214
+
!!! error TS2322: 'Derived[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived[]'.
Types of parameters 'arg' and 'arg' are incompatible.
17
18
Type 'Base' is not assignable to type 'T'.
19
+
'Base' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'.
18
20
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(58,9): error TS2322: Type '(...x: Base[]) => Base' is not assignable to type '<T extends Derived>(...x: T[]) => T'.
19
21
Type 'Base' is not assignable to type 'T'.
20
22
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(62,9): error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '<T extends Derived>(x: T, y: T) => T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(89,9): error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
46
48
Type 'string[]' is not assignable to type 'T[]'.
47
49
Type 'string' is not assignable to type 'T'.
50
+
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
48
51
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(90,9): error TS2322: Type '<T>(x: T) => T[]' is not assignable to type '<T>(x: T) => string[]'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(96,9): error TS2322: Type '<T>(x: T) => string[]' is not assignable to type '<T>(x: T) => T[]'.
55
58
Type 'string[]' is not assignable to type 'T[]'.
56
59
Type 'string' is not assignable to type 'T'.
60
+
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.
0 commit comments