Skip to content

Commit cb4d663

Browse files
committed
fix incorrect error message
1 parent d256fd4 commit cb4d663

File tree

7 files changed

+14
-205
lines changed

7 files changed

+14
-205
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,14 +3752,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37523752
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
37533753
if (meaning & SymbolFlags.Value) {
37543754
if (isPrimitiveTypeName(name)) {
3755+
// const grandparent = errorLocation.parent.parent;
3756+
// const parentOfGrandparent = grandparent.parent;
37553757
if (isExtendedByInterface(errorLocation)) {
37563758
error(errorLocation, Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
37573759
}
37583760
else if (isExtendedByClass(errorLocation)) {
37593761
error(errorLocation, Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values, unescapeLeadingUnderscores(name));
37603762
}
37613763
else if (isImplementedByClass(errorLocation)) {
3762-
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_extend_other_named_object_types, unescapeLeadingUnderscores(name));
3764+
error(errorLocation, Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types, unescapeLeadingUnderscores(name));
37633765
}
37643766
else {
37653767
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here, unescapeLeadingUnderscores(name));
@@ -3784,7 +3786,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37843786
}
37853787
return false;
37863788
}
3787-
3789+
37883790
function isExtendedByInterface(node: Node): boolean {
37893791
const grandparent = node.parent.parent;
37903792
const parentOfGrandparent = grandparent.parent;

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3667,7 +3667,7 @@
36673667
"category": "Error",
36683668
"code": 2855
36693669
},
3670-
"A class cannot implement a primitive type like '{0}'. It can only extend other named object types.": {
3670+
"A class cannot implement a primitive type like '{0}'. It can only implement other named object types.": {
36713671
"category": "Error",
36723672
"code": 2856
36733673
},
Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,17 @@
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.
4-
classImplementsPrimitive.ts(6,21): error TS2304: Cannot find name 'Void'.
5-
classImplementsPrimitive.ts(7,7): error TS2300: Duplicate identifier 'C4a'.
6-
classImplementsPrimitive.ts(7,22): error TS1109: Expression expected.
7-
classImplementsPrimitive.ts(8,21): error TS2304: Cannot find name 'Null'.
8-
classImplementsPrimitive.ts(9,7): error TS2300: Duplicate identifier 'C5a'.
9-
classImplementsPrimitive.ts(9,22): error TS2500: A class can only implement an identifier/qualified-name with optional type arguments.
10-
classImplementsPrimitive.ts(10,21): error TS2749: 'undefined' refers to a value, but is being used as a type here. Did you mean 'typeof undefined'?
11-
classImplementsPrimitive.ts(11,21): error TS2304: Cannot find name 'Undefined'.
12-
classImplementsPrimitive.ts(14,21): error TS2422: A class can only implement an object type or intersection of object types with statically known members.
13-
classImplementsPrimitive.ts(16,7): error TS2300: Duplicate identifier 'C4a'.
14-
classImplementsPrimitive.ts(16,22): error TS1109: Expression expected.
15-
classImplementsPrimitive.ts(17,7): error TS2300: Duplicate identifier 'C5a'.
16-
classImplementsPrimitive.ts(17,22): error TS2500: A class can only implement an identifier/qualified-name with optional type arguments.
1+
classImplementsPrimitive.ts(3,20): error TS2856: A class cannot implement a primitive type like 'number'. It can only implement other named object types.
2+
classImplementsPrimitive.ts(4,21): error TS2856: A class cannot implement a primitive type like 'string'. It can only implement other named object types.
3+
classImplementsPrimitive.ts(5,21): error TS2856: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types.
174

185

19-
==== classImplementsPrimitive.ts (16 errors) ====
6+
==== classImplementsPrimitive.ts (3 errors) ====
207
// classes cannot implement primitives
218

229
class C implements number { }
2310
~~~~~~
24-
!!! error TS2856: A class cannot implement a primitive type like 'number'. It can only extend other named object types.
11+
!!! error TS2856: A class cannot implement a primitive type like 'number'. It can only implement other named object types.
2512
class C2 implements string { }
2613
~~~~~~
27-
!!! error TS2856: A class cannot implement a primitive type like 'string'. It can only extend other named object types.
14+
!!! error TS2856: A class cannot implement a primitive type like 'string'. It can only implement other named object types.
2815
class C3 implements boolean { }
2916
~~~~~~~
30-
!!! error TS2856: A class cannot implement a primitive type like 'boolean'. It can only extend other named object types.
31-
class C4 implements Void { }
32-
~~~~
33-
!!! error TS2304: Cannot find name 'Void'.
34-
class C4a implements void {}
35-
~~~
36-
!!! error TS2300: Duplicate identifier 'C4a'.
37-
~~~~
38-
!!! error TS1109: Expression expected.
39-
class C5 implements Null { }
40-
~~~~
41-
!!! error TS2304: Cannot find name 'Null'.
42-
class C5a implements null { }
43-
~~~
44-
!!! error TS2300: Duplicate identifier 'C5a'.
45-
~~~~
46-
!!! error TS2500: A class can only implement an identifier/qualified-name with optional type arguments.
47-
class C6 implements undefined { }
48-
~~~~~~~~~
49-
!!! error TS2749: 'undefined' refers to a value, but is being used as a type here. Did you mean 'typeof undefined'?
50-
class C7 implements Undefined { }
51-
~~~~~~~~~
52-
!!! error TS2304: Cannot find name 'Undefined'.
53-
54-
enum E { A }
55-
class C8 implements E { }
56-
~
57-
!!! error TS2422: A class can only implement an object type or intersection of object types with statically known members.
58-
59-
class C4a implements void {}
60-
~~~
61-
!!! error TS2300: Duplicate identifier 'C4a'.
62-
~~~~
63-
!!! error TS1109: Expression expected.
64-
class C5a implements null { }
65-
~~~
66-
!!! error TS2300: Duplicate identifier 'C5a'.
67-
~~~~
68-
!!! error TS2500: A class can only implement an identifier/qualified-name with optional type arguments.
17+
!!! error TS2856: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types.

tests/baselines/reference/classImplementsPrimitive.js

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,7 @@
55

66
class C implements number { }
77
class C2 implements string { }
8-
class C3 implements boolean { }
9-
class C4 implements Void { }
10-
class C4a implements void {}
11-
class C5 implements Null { }
12-
class C5a implements null { }
13-
class C6 implements undefined { }
14-
class C7 implements Undefined { }
15-
16-
enum E { A }
17-
class C8 implements E { }
18-
19-
class C4a implements void {}
20-
class C5a implements null { }
8+
class C3 implements boolean { }
219

2210
//// [classImplementsPrimitive.js]
2311
// classes cannot implement primitives
@@ -36,54 +24,3 @@ var C3 = /** @class */ (function () {
3624
}
3725
return C3;
3826
}());
39-
var C4 = /** @class */ (function () {
40-
function C4() {
41-
}
42-
return C4;
43-
}());
44-
var C4a = /** @class */ (function () {
45-
function C4a() {
46-
}
47-
return C4a;
48-
}());
49-
void {};
50-
var C5 = /** @class */ (function () {
51-
function C5() {
52-
}
53-
return C5;
54-
}());
55-
var C5a = /** @class */ (function () {
56-
function C5a() {
57-
}
58-
return C5a;
59-
}());
60-
var C6 = /** @class */ (function () {
61-
function C6() {
62-
}
63-
return C6;
64-
}());
65-
var C7 = /** @class */ (function () {
66-
function C7() {
67-
}
68-
return C7;
69-
}());
70-
var E;
71-
(function (E) {
72-
E[E["A"] = 0] = "A";
73-
})(E || (E = {}));
74-
var C8 = /** @class */ (function () {
75-
function C8() {
76-
}
77-
return C8;
78-
}());
79-
var C4a = /** @class */ (function () {
80-
function C4a() {
81-
}
82-
return C4a;
83-
}());
84-
void {};
85-
var C5a = /** @class */ (function () {
86-
function C5a() {
87-
}
88-
return C5a;
89-
}());

tests/baselines/reference/classImplementsPrimitive.symbols

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,3 @@ class C2 implements string { }
1212
class C3 implements boolean { }
1313
>C3 : Symbol(C3, Decl(classImplementsPrimitive.ts, 3, 30))
1414

15-
class C4 implements Void { }
16-
>C4 : Symbol(C4, Decl(classImplementsPrimitive.ts, 4, 31))
17-
18-
class C4a implements void {}
19-
>C4a : Symbol(C4a, Decl(classImplementsPrimitive.ts, 5, 29))
20-
21-
class C5 implements Null { }
22-
>C5 : Symbol(C5, Decl(classImplementsPrimitive.ts, 6, 28))
23-
24-
class C5a implements null { }
25-
>C5a : Symbol(C5a, Decl(classImplementsPrimitive.ts, 7, 28))
26-
27-
class C6 implements undefined { }
28-
>C6 : Symbol(C6, Decl(classImplementsPrimitive.ts, 8, 29))
29-
30-
class C7 implements Undefined { }
31-
>C7 : Symbol(C7, Decl(classImplementsPrimitive.ts, 9, 33))
32-
33-
enum E { A }
34-
>E : Symbol(E, Decl(classImplementsPrimitive.ts, 10, 33))
35-
>A : Symbol(E.A, Decl(classImplementsPrimitive.ts, 12, 8))
36-
37-
class C8 implements E { }
38-
>C8 : Symbol(C8, Decl(classImplementsPrimitive.ts, 12, 12))
39-
>E : Symbol(E, Decl(classImplementsPrimitive.ts, 10, 33))
40-
41-
class C4a implements void {}
42-
>C4a : Symbol(C4a, Decl(classImplementsPrimitive.ts, 13, 25))
43-
44-
class C5a implements null { }
45-
>C5a : Symbol(C5a, Decl(classImplementsPrimitive.ts, 15, 28))
46-

tests/baselines/reference/classImplementsPrimitive.types

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,3 @@ class C2 implements string { }
1212
class C3 implements boolean { }
1313
>C3 : C3
1414

15-
class C4 implements Void { }
16-
>C4 : C4
17-
18-
class C4a implements void {}
19-
>C4a : C4a
20-
>void {} : undefined
21-
>{} : {}
22-
23-
class C5 implements Null { }
24-
>C5 : C5
25-
26-
class C5a implements null { }
27-
>C5a : C5a
28-
29-
class C6 implements undefined { }
30-
>C6 : C6
31-
32-
class C7 implements Undefined { }
33-
>C7 : C7
34-
35-
enum E { A }
36-
>E : E
37-
>A : E.A
38-
39-
class C8 implements E { }
40-
>C8 : C8
41-
42-
class C4a implements void {}
43-
>C4a : C4a
44-
>void {} : undefined
45-
>{} : {}
46-
47-
class C5a implements null { }
48-
>C5a : C5a
49-

tests/cases/compiler/classImplementsPrimitive.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,4 @@
22

33
class C implements number { }
44
class C2 implements string { }
5-
class C3 implements boolean { }
6-
class C4 implements Void { }
7-
class C4a implements void {}
8-
class C5 implements Null { }
9-
class C5a implements null { }
10-
class C6 implements undefined { }
11-
class C7 implements Undefined { }
12-
13-
enum E { A }
14-
class C8 implements E { }
15-
16-
class C4a implements void {}
17-
class C5a implements null { }
5+
class C3 implements boolean { }

0 commit comments

Comments
 (0)