Skip to content

Commit 3ba257f

Browse files
authored
fix: diagnostic message for class name 'Object' when targeting different ECMAScript versions (#61850)
1 parent 666ef27 commit 3ba257f

17 files changed

+32
-32
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46645,7 +46645,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4664546645
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
4664646646
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
4664746647
) {
46648-
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
46648+
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_and_above_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
4664946649
}
4665046650
}
4665146651

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@
34233423
"category": "Error",
34243424
"code": 2724
34253425
},
3426-
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
3426+
"Class name cannot be 'Object' when targeting ES5 and above with module {0}.": {
34273427
"category": "Error",
34283428
"code": 2725
34293429
},

tests/baselines/reference/checkForObjectTooStrict.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
checkForObjectTooStrict.ts(3,18): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
1+
checkForObjectTooStrict.ts(3,18): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
22

33

44
==== checkForObjectTooStrict.ts (1 errors) ====
55
module Foo {
66

77
export class Object {
88
~~~~~~
9-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
9+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
1010

1111
}
1212

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
exportClassNameWithObjectAMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
1+
exportClassNameWithObjectAMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module AMD.
22

33

44
==== exportClassNameWithObjectAMD.ts (1 errors) ====
55
export class Object {}
66
~~~~~~
7-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
7+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module AMD.
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
exportClassNameWithObjectCommonJS.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
1+
exportClassNameWithObjectCommonJS.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
22

33

44
==== exportClassNameWithObjectCommonJS.ts (1 errors) ====
55
export class Object {}
66
~~~~~~
7-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
7+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
exportClassNameWithObjectSystem.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
1+
exportClassNameWithObjectSystem.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module System.
22

33

44
==== exportClassNameWithObjectSystem.ts (1 errors) ====
55
export class Object {}
66
~~~~~~
7-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
7+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module System.
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
exportClassNameWithObjectUMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
1+
exportClassNameWithObjectUMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module UMD.
22

33

44
==== exportClassNameWithObjectUMD.ts (1 errors) ====
55
export class Object {}
66
~~~~~~
7-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
7+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module UMD.
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
exportDefaultClassNameWithObject.ts(1,22): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
1+
exportDefaultClassNameWithObject.ts(1,22): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
22

33

44
==== exportDefaultClassNameWithObject.ts (1 errors) ====
55
export default class Object {}
66
~~~~~~
7-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
7+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
88

tests/baselines/reference/instanceofOperator.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
instanceofOperator.ts(7,11): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
1+
instanceofOperator.ts(7,11): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
22
instanceofOperator.ts(12,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
33
instanceofOperator.ts(15,20): error TS2359: The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method.
44
instanceofOperator.ts(16,23): error TS2359: The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method.
@@ -15,7 +15,7 @@ instanceofOperator.ts(21,5): error TS2358: The left-hand side of an 'instanceof'
1515
module test {
1616
class Object { }
1717
~~~~~~
18-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
18+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
1919
var obj: Object;
2020

2121

tests/baselines/reference/nodeModulesAllowJsGeneratedNameCollisions(module=node16).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
subfolder/index.js(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
22
subfolder/index.js(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
3-
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node16.
3+
subfolder/index.js(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
44
subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
55

66

@@ -14,7 +14,7 @@ subfolder/index.js(5,14): error TS1216: Identifier expected. '__esModule' is res
1414
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
1515
class Object {}
1616
~~~~~~
17-
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node16.
17+
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node16.
1818
export const __esModule = false;
1919
~~~~~~~~~~
2020
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

0 commit comments

Comments
 (0)