Skip to content

Commit f05f118

Browse files
committed
Fix incorrect error messages
1 parent b4a4014 commit f05f118

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
@@ -3789,13 +3789,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37893789
if (meaning & SymbolFlags.Value) {
37903790
if (isPrimitiveTypeName(name)) {
37913791
if (isExtendedByInterface(errorLocation)) {
3792-
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_an_interface_can_only_extend_named_types_and_classes, unescapeLeadingUnderscores(name));
3792+
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
37933793
}
37943794
else if (isExtendedByClass(errorLocation)) {
3795-
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_a_class_can_only_extend_named_types_and_classes, unescapeLeadingUnderscores(name));
3795+
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
37963796
}
37973797
else if (isImplementedByClass(errorLocation)) {
3798-
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_a_class_can_only_implement_interfaces, unescapeLeadingUnderscores(name));
3798+
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
37993799
}
38003800
else {
38013801
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3835,7 +3835,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38353835
function isExtendedByClass(node: Node): boolean {
38363836
const grandparent = node.parent.parent;
38373837
const parentOfGrandparent = grandparent.parent;
3838-
if(grandparent && parentOfGrandparent){
3838+
if (grandparent && parentOfGrandparent) {
38393839
const isExtending = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ExtendsKeyword;
38403840
const isClass = isClassDeclaration(parentOfGrandparent);
38413841
return isExtending && isClass;
@@ -3846,7 +3846,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
38463846
function isImplementedByClass(node: Node): boolean {
38473847
const grandparent = node.parent.parent;
38483848
const parentOfGrandparent = grandparent.parent;
3849-
if(grandparent && parentOfGrandparent){
3849+
if (grandparent && parentOfGrandparent) {
38503850
const isImplementing = isHeritageClause(grandparent) && grandparent.token === SyntaxKind.ImplementsKeyword;
38513851
const isClass = isClassDeclaration(parentOfGrandparent);
38523852
return isImplementing && isClass;

src/compiler/diagnosticMessages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,7 +3619,7 @@
36193619
"category": "Error",
36203620
"code": 2839
36213621
},
3622-
"An interface cannot extend a primitive type like '{0}'; an interface can only extend named types and classes.": {
3622+
"An interface cannot extend a primitive type like '{0}'. It can only extend other named object types.": {
36233623
"category": "Error",
36243624
"code": 2840
36253625
},
@@ -3699,11 +3699,11 @@
36993699
"category": "Error",
37003700
"code": 2861
37013701
},
3702-
"A class cannot extend a primitive type like '{0}'; a class can only extend named types and classes.": {
3702+
"A class cannot extend a primitive type like '{0}'. Classes can only extend constructable values.": {
37033703
"category": "Error",
37043704
"code": 2862
37053705
},
3706-
"A class cannot implement a primitive type like '{0}'; a class can only implement interfaces.": {
3706+
"A class cannot implement a primitive type like '{0}'. It can only extend other named object types.": {
37073707
"category": "Error",
37083708
"code": 2863
37093709
},

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)