Skip to content

Commit bc3d515

Browse files
committed
Add related info suggesting a fix
1 parent 16f9460 commit bc3d515

18 files changed

+29
-0
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -16918,6 +16918,9 @@ namespace ts {
1691816918
return result;
1691916919
}
1692016920
reportRelationError(headMessage, source, target);
16921+
if (source.flags & TypeFlags.TypeVariable && source.symbol?.declarations?.[0] && !getConstraintOfType(<TypeVariable>source) && isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
16922+
associateRelatedInfo(createDiagnosticForNode(source.symbol.declarations[0], Diagnostics.This_type_parameter_likely_needs_an_extends_object_constraint));
16923+
}
1692116924
}
1692216925
}
1692316926
}

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,10 @@
30593059
"category": "Error",
30603060
"code": 2796
30613061
},
3062+
"This type parameter likely needs an `extends object` constraint.": {
3063+
"category": "Error",
3064+
"code": 2797
3065+
},
30623066

30633067
"Import declaration '{0}' is using private name '{1}'.": {
30643068
"category": "Error",

tests/baselines/reference/bestCommonTypeOfConditionalExpressions.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC
3131
~~~~~~~~~~~~~~~~~~~~
3232
!!! error TS2322: Type 'T | U' is not assignable to type 'Object'.
3333
!!! error TS2322: Type 'T' is not assignable to type 'Object'.
34+
!!! related TS2797 tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions.ts:24:15: This type parameter likely needs an `extends object` constraint.
3435
}

tests/baselines/reference/complexRecursiveCollections.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ tests/cases/compiler/immutable.ts(391,22): error TS2430: Interface 'Set<T>' inco
298298
export function Record<T>(defaultValues: T, name?: string): Record.Class<T>;
299299
~
300300
!!! error TS2344: Type 'T' does not satisfy the constraint 'Object'.
301+
!!! related TS2797 tests/cases/compiler/immutable.ts:261:26: This type parameter likely needs an `extends object` constraint.
301302
export module Seq {
302303
function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed<any> | Seq.Keyed<any, any>;
303304
function of<T>(...values: Array<T>): Seq.Indexed<T>;

tests/baselines/reference/constructorReturningAPrimitive.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tests/cases/compiler/constructorReturningAPrimitive.ts(15,9): error TS2409: Retu
2020
return x;
2121
~~~~~~~~~
2222
!!! error TS2322: Type 'T' is not assignable to type 'B<T>'.
23+
!!! related TS2797 tests/cases/compiler/constructorReturningAPrimitive.ts:12:9: This type parameter likely needs an `extends object` constraint.
2324
~~~~~~~~~
2425
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
2526
}

tests/baselines/reference/keyofAndIndexedAccess.errors.txt

+3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(619,13): error TS23
356356
a = x;
357357
~
358358
!!! error TS2322: Type 'T' is not assignable to type '{}'.
359+
!!! related TS2797 tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts:314:14: This type parameter likely needs an `extends object` constraint.
359360
a = y;
360361
~
361362
!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'.
@@ -373,6 +374,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts(619,13): error TS23
373374
~
374375
!!! error TS2322: Type 'T' is not assignable to type '{} | null | undefined'.
375376
!!! error TS2322: Type 'T' is not assignable to type '{}'.
377+
!!! related TS2797 tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts:321:14: This type parameter likely needs an `extends object` constraint.
378+
!!! related TS2797 tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts:321:14: This type parameter likely needs an `extends object` constraint.
376379
a = y;
377380
~
378381
!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{} | null | undefined'.

tests/baselines/reference/logicalOrOperatorWithTypeParameters.errors.txt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrO
1313
~~
1414
!!! error TS2322: Type 'T | U' is not assignable to type '{}'.
1515
!!! error TS2322: Type 'T' is not assignable to type '{}'.
16+
!!! related TS2797 tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrOperatorWithTypeParameters.ts:1:14: This type parameter likely needs an `extends object` constraint.
1617
}
1718

1819
function fn2<T, U/* extends T*/, V/* extends T*/>(t: T, u: U, v: V) {
@@ -25,6 +26,7 @@ tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrO
2526
~~
2627
!!! error TS2322: Type 'U | V' is not assignable to type '{}'.
2728
!!! error TS2322: Type 'U' is not assignable to type '{}'.
29+
!!! related TS2797 tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrOperatorWithTypeParameters.ts:8:17: This type parameter likely needs an `extends object` constraint.
2830
//var r7: T = u || v;
2931
}
3032

tests/baselines/reference/mappedTypesAndObjects.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts(25,11): error TS24
3333
!!! error TS2430: Interface 'E1<T>' incorrectly extends interface 'Base'.
3434
!!! error TS2430: Types of property 'foo' are incompatible.
3535
!!! error TS2430: Type 'T' is not assignable to type '{ [key: string]: any; }'.
36+
!!! related TS2797 tests/cases/conformance/types/mapped/mappedTypesAndObjects.ts:25:14: This type parameter likely needs an `extends object` constraint.
3637
foo: T;
3738
}
3839

tests/baselines/reference/subclassThisTypeAssignable.errors.txt

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tests/cases/compiler/tile1.ts(11,40): error TS2344: Type 'State' does not satisf
88
oninit?(vnode: Vnode<Attrs, State>): number;
99
~~~~~
1010
!!! error TS2344: Type 'State' does not satisfy the constraint 'Lifecycle<Attrs, State>'.
11+
!!! related TS2797 tests/cases/compiler/tile1.ts:1:28: This type parameter likely needs an `extends object` constraint.
1112
[_: number]: any;
1213
}
1314

@@ -21,6 +22,7 @@ tests/cases/compiler/tile1.ts(11,40): error TS2344: Type 'State' does not satisf
2122
view(this: State, vnode: Vnode<Attrs, State>): number;
2223
~~~~~
2324
!!! error TS2344: Type 'State' does not satisfy the constraint 'Lifecycle<Attrs, State>'.
25+
!!! related TS2797 tests/cases/compiler/tile1.ts:10:28: This type parameter likely needs an `extends object` constraint.
2426
}
2527

2628
interface ClassComponent<A> extends Lifecycle<A, ClassComponent<A>> {

tests/baselines/reference/subtypingWithOptionalProperties.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
99
var b: { s?: number } = a;
1010
~
1111
!!! error TS2322: Type 'T' is not assignable to type '{ s?: number; }'.
12+
!!! related TS2797 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithOptionalProperties.ts:4:12: This type parameter likely needs an `extends object` constraint.
1213
return b;
1314
}
1415

tests/baselines/reference/tsxGenericAttributesType5.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2416: Property 'props' in typ
1717
!!! error TS2416: Property 'props' in type 'B<U>' is not assignable to the same property in base type 'Component<U, {}>'.
1818
!!! error TS2416: Type 'U' is not assignable to type 'U & { children?: ReactNode; }'.
1919
!!! error TS2416: Type 'U' is not assignable to type '{ children?: ReactNode; }'.
20+
!!! related TS2797 tests/cases/conformance/jsx/file.tsx:8:9: This type parameter likely needs an `extends object` constraint.
2021
render() {
2122
return <B1 {...this.props} x="hi" />;
2223
}

tests/baselines/reference/tsxGenericAttributesType6.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tests/cases/conformance/jsx/file.tsx(9,5): error TS2416: Property 'props' in typ
1717
!!! error TS2416: Property 'props' in type 'B<U>' is not assignable to the same property in base type 'Component<U, {}>'.
1818
!!! error TS2416: Type 'U' is not assignable to type 'U & { children?: ReactNode; }'.
1919
!!! error TS2416: Type 'U' is not assignable to type '{ children?: ReactNode; }'.
20+
!!! related TS2797 tests/cases/conformance/jsx/file.tsx:8:9: This type parameter likely needs an `extends object` constraint.
2021
render() {
2122
return <B1 {...this.props} x="hi" />;
2223
}

tests/baselines/reference/tsxGenericAttributesType7.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tests/cases/conformance/jsx/file.tsx(5,13): error TS2322: Type 'U' is not assign
1111
~~~~~~~~~
1212
!!! error TS2322: Type 'U' is not assignable to type 'IntrinsicAttributes & U'.
1313
!!! error TS2322: Type 'U' is not assignable to type 'IntrinsicAttributes'.
14+
!!! related TS2797 tests/cases/conformance/jsx/file.tsx:4:29: This type parameter likely needs an `extends object` constraint.
1415
}
1516

1617
const decorator1 = function <U extends {x: string}>(props: U) {

tests/baselines/reference/tsxGenericAttributesType8.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tests/cases/conformance/jsx/file.tsx(5,13): error TS2322: Type 'U' is not assign
1111
~~~~~~~~~
1212
!!! error TS2322: Type 'U' is not assignable to type 'IntrinsicAttributes & U'.
1313
!!! error TS2322: Type 'U' is not assignable to type 'IntrinsicAttributes'.
14+
!!! related TS2797 tests/cases/conformance/jsx/file.tsx:4:29: This type parameter likely needs an `extends object` constraint.
1415
}
1516

1617
const decorator1 = function <U extends {x: string}>(props: U) {

tests/baselines/reference/tsxNotUsingApparentTypeOfSFC.errors.txt

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ tests/cases/compiler/tsxNotUsingApparentTypeOfSFC.tsx(18,14): error TS2769: No o
4646
~~~~~
4747
!!! error TS2322: Type 'P' is not assignable to type 'IntrinsicAttributes & P'.
4848
!!! error TS2322: Type 'P' is not assignable to type 'IntrinsicAttributes'.
49+
!!! related TS2797 tests/cases/compiler/tsxNotUsingApparentTypeOfSFC.tsx:5:15: This type parameter likely needs an `extends object` constraint.
4950
let q = <MyComponent {...wrappedProps} /> // should work
5051
~~~~~~~~~~~
5152
!!! error TS2769: No overload matches this call.
@@ -55,4 +56,6 @@ tests/cases/compiler/tsxNotUsingApparentTypeOfSFC.tsx(18,14): error TS2769: No o
5556
!!! error TS2769: Overload 2 of 2, '(props: P, context?: any): MyComponent', gave the following error.
5657
!!! error TS2769: Type 'P' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComponent> & Readonly<{ children?: ReactNode; }> & Readonly<P>'.
5758
!!! error TS2769: Type 'P' is not assignable to type 'IntrinsicAttributes'.
59+
!!! related TS2797 tests/cases/compiler/tsxNotUsingApparentTypeOfSFC.tsx:5:15: This type parameter likely needs an `extends object` constraint.
60+
!!! related TS2797 tests/cases/compiler/tsxNotUsingApparentTypeOfSFC.tsx:5:15: This type parameter likely needs an `extends object` constraint.
5861
}

tests/baselines/reference/tsxStatelessFunctionComponentsWithTypeArguments2.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tests/cases/conformance/jsx/file.tsx(31,52): error TS2322: Type '(val: string) =
2727
~~~~~~~~~~~~~~~~~~
2828
!!! error TS2322: Type 'T' is not assignable to type 'IntrinsicAttributes & { prop: unknown; "ignore-prop": string; }'.
2929
!!! error TS2322: Type 'T' is not assignable to type 'IntrinsicAttributes'.
30+
!!! related TS2797 tests/cases/conformance/jsx/file.tsx:12:14: This type parameter likely needs an `extends object` constraint.
3031
}
3132

3233
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;

tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(6,5): error TS2322: Type
2222
z = x; // Ok
2323
~
2424
!!! error TS2322: Type 'T' is not assignable to type 'Object'.
25+
!!! related TS2797 tests/cases/compiler/typeParametersShouldNotBeEqual.ts:1:13: This type parameter likely needs an `extends object` constraint.
2526
}
2627

tests/baselines/reference/unknownType1.errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type
259259
let x: {} = t;
260260
~
261261
!!! error TS2322: Type 'T' is not assignable to type '{}'.
262+
!!! related TS2797 tests/cases/conformance/types/unknown/unknownType1.ts:169:14: This type parameter likely needs an `extends object` constraint.
262263
let y: {} = u;
263264
~
264265
!!! error TS2322: Type 'U' is not assignable to type '{}'.

0 commit comments

Comments
 (0)