Skip to content

Commit d256fd4

Browse files
committed
Fix incorrect error messages
1 parent 3a8c68f commit d256fd4

8 files changed

+28
-28
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,13 +3753,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37533753
if (meaning & SymbolFlags.Value) {
37543754
if (isPrimitiveTypeName(name)) {
37553755
if (isExtendedByInterface(errorLocation)) {
3756-
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes, unescapeLeadingUnderscores(name));
3756+
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
37573757
}
37583758
else if (isExtendedByClass(errorLocation)) {
3759-
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_a_class_can_only_extend_named_types_and_classes, unescapeLeadingUnderscores(name));
3759+
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
37603760
}
37613761
else if (isImplementedByClass(errorLocation)) {
3762-
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_a_class_can_only_implement_interfaces, unescapeLeadingUnderscores(name));
3762+
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
37633763
}
37643764
else {
37653765
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3799,7 +3799,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37993799
function isExtendedByClass(node: Node): boolean {
38003800
const grandparent = node.parent.parent;
38013801
const parentOfGrandparent = grandparent.parent;
3802-
if(grandparent && parentOfGrandparent){
3802+
if (grandparent && parentOfGrandparent) {
38033803
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
38043804
const isClass = isClassDeclaration(parentOfGrandparent);
38053805
return isExtending && isClass;
@@ -3810,7 +3810,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38103810
function isImplementedByClass(node: Node): boolean {
38113811
const grandparent = node.parent.parent;
38123812
const parentOfGrandparent = grandparent.parent;
3813-
if(grandparent && parentOfGrandparent){
3813+
if (grandparent && parentOfGrandparent) {
38143814
const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
38153815
const isClass = isClassDeclaration(parentOfGrandparent);
38163816
return isImplementing && isClass;

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,7 @@
36073607
"category": "Error",
36083608
"code": 2839
36093609
},
3610-
"An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes.": {
3610+
"An interface cannot extend a primitive type like '{0}'. It can only extend other named object types.": {
36113611
"category": "Error",
36123612
"code": 2840
36133613
},
@@ -3663,11 +3663,11 @@
36633663
"category": "Error",
36643664
"code": 2854
36653665
},
3666-
"A class cannot extend a primitive type like '{0}'; a class can only extend named types and classes.": {
3666+
"A class cannot extend a primitive type like '{0}'. Classes can only extend constructable values.": {
36673667
"category": "Error",
36683668
"code": 2855
36693669
},
3670-
"A class cannot implement a primitive type like '{0}'; a class can only implement interfaces.": {
3670+
"A class cannot implement a primitive type like '{0}'. It can only extend other named object types.": {
36713671
"category": "Error",
36723672
"code": 2856
36733673
},

tests/baselines/reference/classExtendingPrimitive.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
classExtendingPrimitive.ts(3,17): error TS2855: A class cannot extend a primitive type like 'number'; a class can only extend named types and classes.
2-
classExtendingPrimitive.ts(4,18): error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
3-
classExtendingPrimitive.ts(5,18): error TS2855: A class cannot extend a primitive type like 'boolean'; a class can only extend named types and classes.
1+
classExtendingPrimitive.ts(3,17): error TS2855: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values.
2+
classExtendingPrimitive.ts(4,18): error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
3+
classExtendingPrimitive.ts(5,18): error TS2855: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values.
44
classExtendingPrimitive.ts(6,18): error TS2304: Cannot find name 'Void'.
55
classExtendingPrimitive.ts(7,19): error TS1109: Expression expected.
66
classExtendingPrimitive.ts(8,18): error TS2304: Cannot find name 'Null'.
@@ -14,13 +14,13 @@ classExtendingPrimitive.ts(14,18): error TS2507: Type 'typeof E' is not a constr
1414

1515
class C extends number { }
1616
~~~~~~
17-
!!! error TS2855: A class cannot extend a primitive type like 'number'; a class can only extend named types and classes.
17+
!!! error TS2855: A class cannot extend a primitive type like 'number'. Classes can only extend constructable values.
1818
class C2 extends string { }
1919
~~~~~~
20-
!!! error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
20+
!!! error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
2121
class C3 extends boolean { }
2222
~~~~~~~
23-
!!! error TS2855: A class cannot extend a primitive type like 'boolean'; a class can only extend named types and classes.
23+
!!! error TS2855: A class cannot extend a primitive type like 'boolean'. Classes can only extend constructable values.
2424
class C4 extends Void { }
2525
~~~~
2626
!!! error TS2304: Cannot find name 'Void'.

tests/baselines/reference/classImplementsPrimitive.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
classImplementsPrimitive.ts(3,20): error TS2856: A class cannot implement a primitive type like 'number'; a class can only implement interfaces.
2-
classImplementsPrimitive.ts(4,21): error TS2856: A class cannot implement a primitive type like 'string'; a class can only implement interfaces.
3-
classImplementsPrimitive.ts(5,21): error TS2856: A class cannot implement a primitive type like 'boolean'; a class can only implement interfaces.
1+
classImplementsPrimitive.ts(3,20): error TS2856: A class cannot implement a primitive type like 'number'. It can only extend other named object types.
2+
classImplementsPrimitive.ts(4,21): error TS2856: A class cannot implement a primitive type like 'string'. It can only extend other named object types.
3+
classImplementsPrimitive.ts(5,21): error TS2856: A class cannot implement a primitive type like 'boolean'. It can only extend other named object types.
44
classImplementsPrimitive.ts(6,21): error TS2304: Cannot find name 'Void'.
55
classImplementsPrimitive.ts(7,7): error TS2300: Duplicate identifier 'C4a'.
66
classImplementsPrimitive.ts(7,22): error TS1109: Expression expected.
@@ -21,13 +21,13 @@ classImplementsPrimitive.ts(17,22): error TS2500: A class can only implement an
2121

2222
class C implements number { }
2323
~~~~~~
24-
!!! error TS2856: A class cannot implement a primitive type like 'number'; a class can only implement interfaces.
24+
!!! error TS2856: A class cannot implement a primitive type like 'number'. It can only extend other named object types.
2525
class C2 implements string { }
2626
~~~~~~
27-
!!! error TS2856: A class cannot implement a primitive type like 'string'; a class can only implement interfaces.
27+
!!! error TS2856: A class cannot implement a primitive type like 'string'. It can only extend other named object types.
2828
class C3 implements boolean { }
2929
~~~~~~~
30-
!!! error TS2856: A class cannot implement a primitive type like 'boolean'; a class can only implement interfaces.
30+
!!! error TS2856: A class cannot implement a primitive type like 'boolean'. It can only extend other named object types.
3131
class C4 implements Void { }
3232
~~~~
3333
!!! error TS2304: Cannot find name 'Void'.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
errorLocationForInterfaceExtension.ts(3,21): error TS2840: An interface cannot extend a primitive type like 'string'; an interface can only extend named types and classes.
1+
errorLocationForInterfaceExtension.ts(3,21): error TS2840: An interface cannot extend a primitive type like 'string'. It can only extend other named object types.
22

33

44
==== errorLocationForInterfaceExtension.ts (1 errors) ====
55
var n = '';
66

77
interface x extends string { }
88
~~~~~~
9-
!!! error TS2840: An interface cannot extend a primitive type like 'string'; an interface can only extend named types and classes.
9+
!!! error TS2840: An interface cannot extend a primitive type like 'string'. It can only extend other named object types.
1010

tests/baselines/reference/interfacedeclWithIndexerErrors.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interfacedeclWithIndexerErrors.ts(14,5): error TS2411: Property 'p4' of type 'nu
33
interfacedeclWithIndexerErrors.ts(15,5): error TS2411: Property 'p5' of type '(s: number) => string' is not assignable to 'string' index type '() => string'.
44
interfacedeclWithIndexerErrors.ts(19,5): error TS2411: Property 'f3' of type '(a: string) => number' is not assignable to 'string' index type '() => string'.
55
interfacedeclWithIndexerErrors.ts(20,5): error TS2411: Property 'f4' of type '(s: number) => string' is not assignable to 'string' index type '() => string'.
6-
interfacedeclWithIndexerErrors.ts(44,21): error TS2840: An interface cannot extend a primitive type like 'number'; an interface can only extend named types and classes.
6+
interfacedeclWithIndexerErrors.ts(44,21): error TS2840: An interface cannot extend a primitive type like 'number'. It can only extend other named object types.
77
interfacedeclWithIndexerErrors.ts(48,18): error TS2693: 'string' only refers to a type, but is being used as a value here.
88

99

@@ -63,7 +63,7 @@ interfacedeclWithIndexerErrors.ts(48,18): error TS2693: 'string' only refers to
6363

6464
interface e extends number {
6565
~~~~~~
66-
!!! error TS2840: An interface cannot extend a primitive type like 'number'; an interface can only extend named types and classes.
66+
!!! error TS2840: An interface cannot extend a primitive type like 'number'. It can only extend other named object types.
6767
}
6868

6969
interface f {

tests/baselines/reference/topLevelAwaitErrors.1(module=es2022).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ topLevelAwaitErrors.1.ts(8,14): error TS1005: '>' expected.
66
topLevelAwaitErrors.1.ts(8,16): error TS2693: 'string' only refers to a type, but is being used as a value here.
77
topLevelAwaitErrors.1.ts(11,17): error TS1109: Expression expected.
88
topLevelAwaitErrors.1.ts(11,22): error TS1109: Expression expected.
9-
topLevelAwaitErrors.1.ts(11,23): error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
9+
topLevelAwaitErrors.1.ts(11,23): error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
1010
topLevelAwaitErrors.1.ts(11,29): error TS1005: ',' expected.
1111
topLevelAwaitErrors.1.ts(15,8): error TS1109: Expression expected.
1212
topLevelAwaitErrors.1.ts(18,2): error TS1109: Expression expected.
@@ -49,7 +49,7 @@ topLevelAwaitErrors.1.ts(42,20): error TS1109: Expression expected.
4949
~
5050
!!! error TS1109: Expression expected.
5151
~~~~~~
52-
!!! error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
52+
!!! error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
5353
~
5454
!!! error TS1005: ',' expected.
5555
}

tests/baselines/reference/topLevelAwaitErrors.1(module=esnext).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ topLevelAwaitErrors.1.ts(8,14): error TS1005: '>' expected.
66
topLevelAwaitErrors.1.ts(8,16): error TS2693: 'string' only refers to a type, but is being used as a value here.
77
topLevelAwaitErrors.1.ts(11,17): error TS1109: Expression expected.
88
topLevelAwaitErrors.1.ts(11,22): error TS1109: Expression expected.
9-
topLevelAwaitErrors.1.ts(11,23): error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
9+
topLevelAwaitErrors.1.ts(11,23): error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
1010
topLevelAwaitErrors.1.ts(11,29): error TS1005: ',' expected.
1111
topLevelAwaitErrors.1.ts(15,8): error TS1109: Expression expected.
1212
topLevelAwaitErrors.1.ts(18,2): error TS1109: Expression expected.
@@ -49,7 +49,7 @@ topLevelAwaitErrors.1.ts(42,20): error TS1109: Expression expected.
4949
~
5050
!!! error TS1109: Expression expected.
5151
~~~~~~
52-
!!! error TS2855: A class cannot extend a primitive type like 'string'; a class can only extend named types and classes.
52+
!!! error TS2855: A class cannot extend a primitive type like 'string'. Classes can only extend constructable values.
5353
~
5454
!!! error TS1005: ',' expected.
5555
}

0 commit comments

Comments
 (0)