fix: diagnostic message for class name 'Object' when targeting different ECMAScript versions (#61850)

This commit is contained in:
Idan Goshen
2025-07-01 01:46:33 +03:00
committed by GitHub
parent 666ef27201
commit 3ba257ffac
17 changed files with 32 additions and 32 deletions

View File

@@ -46645,7 +46645,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
) {
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
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
}
}

View File

@@ -3423,7 +3423,7 @@
"category": "Error",
"code": 2724
},
"Class name cannot be 'Object' when targeting ES5 with module {0}.": {
"Class name cannot be 'Object' when targeting ES5 and above with module {0}.": {
"category": "Error",
"code": 2725
},

View File

@@ -1,4 +1,4 @@
checkForObjectTooStrict.ts(3,18): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
checkForObjectTooStrict.ts(3,18): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
==== checkForObjectTooStrict.ts (1 errors) ====
@@ -6,7 +6,7 @@ checkForObjectTooStrict.ts(3,18): error TS2725: Class name cannot be 'Object' wh
export class Object {
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
}

View File

@@ -1,8 +1,8 @@
exportClassNameWithObjectAMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
exportClassNameWithObjectAMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module AMD.
==== exportClassNameWithObjectAMD.ts (1 errors) ====
export class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module AMD.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module AMD.

View File

@@ -1,8 +1,8 @@
exportClassNameWithObjectCommonJS.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
exportClassNameWithObjectCommonJS.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
==== exportClassNameWithObjectCommonJS.ts (1 errors) ====
export class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.

View File

@@ -1,8 +1,8 @@
exportClassNameWithObjectSystem.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
exportClassNameWithObjectSystem.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module System.
==== exportClassNameWithObjectSystem.ts (1 errors) ====
export class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module System.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module System.

View File

@@ -1,8 +1,8 @@
exportClassNameWithObjectUMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
exportClassNameWithObjectUMD.ts(1,14): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module UMD.
==== exportClassNameWithObjectUMD.ts (1 errors) ====
export class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module UMD.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module UMD.

View File

@@ -1,8 +1,8 @@
exportDefaultClassNameWithObject.ts(1,22): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
exportDefaultClassNameWithObject.ts(1,22): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
==== exportDefaultClassNameWithObject.ts (1 errors) ====
export default class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.

View File

@@ -1,4 +1,4 @@
instanceofOperator.ts(7,11): error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
instanceofOperator.ts(7,11): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
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.
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.
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'
module test {
class Object { }
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module CommonJS.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module CommonJS.
var obj: Object;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node18.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node18.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node18.
export const __esModule = false;
~~~~~~~~~~
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

View File

@@ -1,6 +1,6 @@
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node20.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node20.
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module Node20.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module Node20.
export const __esModule = false;
~~~~~~~~~~
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.

View File

@@ -1,6 +1,6 @@
subfolder/index.ts(2,10): error TS2441: Duplicate identifier 'require'. Compiler reserves name 'require' in top level scope of a module.
subfolder/index.ts(3,7): error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 with module NodeNext.
subfolder/index.ts(4,7): error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.
@@ -14,7 +14,7 @@ subfolder/index.ts(5,14): error TS1216: Identifier expected. '__esModule' is res
!!! error TS2441: Duplicate identifier 'exports'. Compiler reserves name 'exports' in top level scope of a module.
class Object {}
~~~~~~
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 with module NodeNext.
!!! error TS2725: Class name cannot be 'Object' when targeting ES5 and above with module NodeNext.
export const __esModule = false;
~~~~~~~~~~
!!! error TS1216: Identifier expected. '__esModule' is reserved as an exported marker when transforming ECMAScript modules.