Skip to content

Commit f4fb28d

Browse files
Merge pull request #28015 from prateekgoel/error-messages
Error messages for extending a specific type
2 parents 89fbaf2 + 15e7fa7 commit f4fb28d

6 files changed

+18
-18
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,7 +5894,7 @@ namespace ts {
58945894
return type.resolvedBaseTypes = emptyArray;
58955895
}
58965896
if (!isValidBaseType(baseType)) {
5897-
error(baseTypeNode.expression, Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType));
5897+
error(baseTypeNode.expression, Diagnostics.Base_constructor_return_type_0_is_not_an_object_type_or_intersection_of_object_types_with_statically_known_members, typeToString(baseType));
58985898
return type.resolvedBaseTypes = emptyArray;
58995899
}
59005900
if (type === baseType || hasBaseType(baseType, type)) {
@@ -5952,7 +5952,7 @@ namespace ts {
59525952
}
59535953
}
59545954
else {
5955-
error(node, Diagnostics.An_interface_may_only_extend_a_class_or_another_interface);
5955+
error(node, Diagnostics.An_interface_can_only_extend_an_object_type_or_intersection_of_object_types_with_statically_known_members);
59565956
}
59575957
}
59585958
}
@@ -26454,7 +26454,7 @@ namespace ts {
2645426454
}
2645526455
}
2645626456
else {
26457-
error(typeRefNode, Diagnostics.A_class_may_only_implement_another_class_or_interface);
26457+
error(typeRefNode, Diagnostics.A_class_can_only_implement_an_object_type_or_intersection_of_object_types_with_statically_known_members);
2645826458
}
2645926459
}
2646026460
}

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@
10601060
"category": "Error",
10611061
"code": 2311
10621062
},
1063-
"An interface may only extend a class or another interface.": {
1063+
"An interface can only extend an object type or intersection of object types with statically known members.": {
10641064
"category": "Error",
10651065
"code": 2312
10661066
},
@@ -1488,7 +1488,7 @@
14881488
"category": "Error",
14891489
"code": 2420
14901490
},
1491-
"A class may only implement another class or interface.": {
1491+
"A class can only implement an object type or intersection of object types with statically known members.": {
14921492
"category": "Error",
14931493
"code": 2422
14941494
},
@@ -1820,7 +1820,7 @@
18201820
"category": "Error",
18211821
"code": 2508
18221822
},
1823-
"Base constructor return type '{0}' is not a class or interface type.": {
1823+
"Base constructor return type '{0}' is not an object type or intersection of object types with statically known members.": {
18241824
"category": "Error",
18251825
"code": 2509
18261826
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/inheritFromGenericTypeParameter.ts(1,20): error TS2304: Cannot find name 'T'.
2-
tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface may only extend a class or another interface.
2+
tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
33

44

55
==== tests/cases/compiler/inheritFromGenericTypeParameter.ts (2 errors) ====
@@ -8,4 +8,4 @@ tests/cases/compiler/inheritFromGenericTypeParameter.ts(2,24): error TS2312: An
88
!!! error TS2304: Cannot find name 'T'.
99
interface I<T> extends T { }
1010
~
11-
!!! error TS2312: An interface may only extend a class or another interface.
11+
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.

tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI
5151
Type 'I23' is not assignable to type 'T1'.
5252
Types of property 'a' are incompatible.
5353
Type 'string' is not assignable to type 'number'.
54-
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(46,23): error TS2312: An interface may only extend a class or another interface.
55-
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface may only extend a class or another interface.
54+
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(46,23): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
55+
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(47,26): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
5656

5757

5858
==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts (23 errors) ====
@@ -177,8 +177,8 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI
177177

178178
interface I30 extends U { x: string }
179179
~
180-
!!! error TS2312: An interface may only extend a class or another interface.
180+
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
181181
interface I31<T> extends T { x: string }
182182
~
183-
!!! error TS2312: An interface may only extend a class or another interface.
183+
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
184184

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/typeParameterAsBaseClass.ts(1,20): error TS2304: Cannot find name 'T'.
2-
tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class may only implement another class or interface.
2+
tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class can only implement an object type or intersection of object types with statically known members.
33

44

55
==== tests/cases/compiler/typeParameterAsBaseClass.ts (2 errors) ====
@@ -8,4 +8,4 @@ tests/cases/compiler/typeParameterAsBaseClass.ts(2,24): error TS2422: A class ma
88
!!! error TS2304: Cannot find name 'T'.
99
class C2<T> implements T {}
1010
~
11-
!!! error TS2422: A class may only implement another class or interface.
11+
!!! error TS2422: A class can only implement an object type or intersection of object types with statically known members.

tests/baselines/reference/typeParameterAsBaseType.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(4,20): error TS2304: Cannot find name 'T'.
22
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(5,24): error TS2304: Cannot find name 'U'.
3-
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface may only extend a class or another interface.
4-
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface may only extend a class or another interface.
3+
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(7,24): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
4+
tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
55

66

77
==== tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts (4 errors) ====
@@ -17,9 +17,9 @@ tests/cases/conformance/types/typeParameters/typeParameterAsBaseType.ts(8,28): e
1717

1818
interface I<T> extends T { }
1919
~
20-
!!! error TS2312: An interface may only extend a class or another interface.
20+
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
2121
interface I2<T, U> extends U { }
2222
~
23-
!!! error TS2312: An interface may only extend a class or another interface.
23+
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
2424

2525

0 commit comments

Comments
 (0)