diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a7ef73e073..e30f4c95a4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17483,7 +17483,7 @@ namespace ts { if (isInPropertyInitializer(node) && !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) && !isPropertyDeclaredInAncestorClass(prop)) { - diagnosticMessage = error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationName); + diagnosticMessage = error(right, Diagnostics.Property_0_is_used_before_its_initialization, declarationName); } else if (valueDeclaration.kind === SyntaxKind.ClassDeclaration && node.parent.kind !== SyntaxKind.TypeReference && diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 540da3826b..e188bbdc45 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2401,6 +2401,10 @@ "category": "Error", "code": 2728 }, + "Property '{0}' is used before its initialization.": { + "category": "Error", + "code": 2729 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5f428dce85..79c0c33170 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5423,6 +5423,7 @@ declare namespace ts { Cannot_find_lib_definition_for_0: DiagnosticMessage; Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage; _0_was_declared_here: DiagnosticMessage; + Property_0_is_used_before_its_initialization: DiagnosticMessage; Import_declaration_0_is_using_private_name_1: DiagnosticMessage; Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage; Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage; diff --git a/tests/baselines/reference/classMergedWithInterfaceMultipleBasesNoError.errors.txt b/tests/baselines/reference/classMergedWithInterfaceMultipleBasesNoError.errors.txt index aa21114b4b..95cc59c69f 100644 --- a/tests/baselines/reference/classMergedWithInterfaceMultipleBasesNoError.errors.txt +++ b/tests/baselines/reference/classMergedWithInterfaceMultipleBasesNoError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2448: Block-scoped variable 'handleIntersection' used before its declaration. +tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): error TS2729: Property 'handleIntersection' is used before its initialization. ==== tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts(8,30): erro export default class extends Foo { readonly observer = this.handleIntersection; ~~~~~~~~~~~~~~~~~~ -!!! error TS2448: Block-scoped variable 'handleIntersection' used before its declaration. +!!! error TS2729: Property 'handleIntersection' is used before its initialization. !!! related TS2728 tests/cases/compiler/classMergedWithInterfaceMultipleBasesNoError.ts:9:14: 'handleIntersection' was declared here. readonly handleIntersection = () => { } } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticInitializersUsePropertiesBeforeDeclaration.errors.txt b/tests/baselines/reference/classStaticInitializersUsePropertiesBeforeDeclaration.errors.txt index abfb42419b..6769f633d3 100644 --- a/tests/baselines/reference/classStaticInitializersUsePropertiesBeforeDeclaration.errors.txt +++ b/tests/baselines/reference/classStaticInitializersUsePropertiesBeforeDeclaration.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,25): error TS2450: Enum 'Enum' used before its declaration. -tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2448: Block-scoped variable 'A' used before its declaration. +tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(2,30): error TS2729: Property 'A' is used before its initialization. tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,31): error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration. -tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2448: Block-scoped variable 'A' used before its declaration. -tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2448: Block-scoped variable 'A' used before its declaration. +tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(3,42): error TS2729: Property 'A' is used before its initialization. +tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4,40): error TS2729: Property 'A' is used before its initialization. ==== tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts (5 errors) ==== @@ -12,18 +12,18 @@ tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts(4, !!! error TS2450: Enum 'Enum' used before its declaration. !!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:7:6: 'Enum' was declared here. ~ -!!! error TS2448: Block-scoped variable 'A' used before its declaration. +!!! error TS2729: Property 'A' is used before its initialization. !!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:8:5: 'A' was declared here. static objLiteralMember = ObjLiteral.A; ~~~~~~~~~~ !!! error TS2448: Block-scoped variable 'ObjLiteral' used before its declaration. !!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:11:7: 'ObjLiteral' was declared here. ~ -!!! error TS2448: Block-scoped variable 'A' used before its declaration. +!!! error TS2729: Property 'A' is used before its initialization. !!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:12:5: 'A' was declared here. static namespaceMember = Namespace.A; ~ -!!! error TS2448: Block-scoped variable 'A' used before its declaration. +!!! error TS2729: Property 'A' is used before its initialization. !!! related TS2728 tests/cases/compiler/classStaticInitializersUsePropertiesBeforeDeclaration.ts:16:16: 'A' was declared here. } diff --git a/tests/baselines/reference/forwardRefInClassProperties.errors.txt b/tests/baselines/reference/forwardRefInClassProperties.errors.txt index 2ce67dd15d..36dfec7646 100644 --- a/tests/baselines/reference/forwardRefInClassProperties.errors.txt +++ b/tests/baselines/reference/forwardRefInClassProperties.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2448: Block-scoped variable '_a' used before its declaration. -tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2448: Block-scoped variable '_A' used before its declaration. +tests/cases/compiler/forwardRefInClassProperties.ts(3,15): error TS2729: Property '_a' is used before its initialization. +tests/cases/compiler/forwardRefInClassProperties.ts(6,22): error TS2729: Property '_A' is used before its initialization. tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block-scoped variable 'b' used before its declaration. @@ -8,19 +8,19 @@ tests/cases/compiler/forwardRefInClassProperties.ts(11,17): error TS2448: Block- { _b = this._a; // undefined, no error/warning ~~ -!!! error TS2448: Block-scoped variable '_a' used before its declaration. +!!! error TS2729: Property '_a' is used before its initialization. !!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:4:5: '_a' was declared here. _a = 3; static _B = Test._A; // undefined, no error/warning ~~ -!!! error TS2448: Block-scoped variable '_A' used before its declaration. +!!! error TS2729: Property '_A' is used before its initialization. !!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:7:12: '_A' was declared here. static _A = 3; method() { - let a = b; // Block-scoped variable 'b' used before its declaration + let a = b; // Property 'b' is used before its initialization. ~ !!! error TS2448: Block-scoped variable 'b' used before its declaration. !!! related TS2728 tests/cases/compiler/forwardRefInClassProperties.ts:12:13: 'b' was declared here. diff --git a/tests/baselines/reference/forwardRefInClassProperties.js b/tests/baselines/reference/forwardRefInClassProperties.js index 48cbd4af6f..02e53e708b 100644 --- a/tests/baselines/reference/forwardRefInClassProperties.js +++ b/tests/baselines/reference/forwardRefInClassProperties.js @@ -9,7 +9,7 @@ class Test method() { - let a = b; // Block-scoped variable 'b' used before its declaration + let a = b; // Property 'b' is used before its initialization. let b = 3; } } @@ -22,7 +22,7 @@ var Test = /** @class */ (function () { this._a = 3; } Test.prototype.method = function () { - var a = b; // Block-scoped variable 'b' used before its declaration + var a = b; // Property 'b' is used before its initialization. var b = 3; }; Test._B = Test._A; // undefined, no error/warning diff --git a/tests/baselines/reference/forwardRefInClassProperties.symbols b/tests/baselines/reference/forwardRefInClassProperties.symbols index bef27dd788..e55d767714 100644 --- a/tests/baselines/reference/forwardRefInClassProperties.symbols +++ b/tests/baselines/reference/forwardRefInClassProperties.symbols @@ -23,7 +23,7 @@ class Test method() >method : Symbol(Test.method, Decl(forwardRefInClassProperties.ts, 6, 18)) { - let a = b; // Block-scoped variable 'b' used before its declaration + let a = b; // Property 'b' is used before its initialization. >a : Symbol(a, Decl(forwardRefInClassProperties.ts, 10, 11)) >b : Symbol(b, Decl(forwardRefInClassProperties.ts, 11, 11)) diff --git a/tests/baselines/reference/forwardRefInClassProperties.types b/tests/baselines/reference/forwardRefInClassProperties.types index d5dc9495b7..ccfa071e43 100644 --- a/tests/baselines/reference/forwardRefInClassProperties.types +++ b/tests/baselines/reference/forwardRefInClassProperties.types @@ -25,7 +25,7 @@ class Test method() >method : () => void { - let a = b; // Block-scoped variable 'b' used before its declaration + let a = b; // Property 'b' is used before its initialization. >a : number >b : number diff --git a/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt b/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt index acf9f8d86c..bcc4965172 100644 --- a/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt +++ b/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2448: Block-scoped variable 'data' used before its declaration. +tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2729: Property 'data' is used before its initialization. tests/cases/compiler/scopeCheckStaticInitializer.ts(5,23): error TS2449: Class 'After' used before its declaration. -tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2448: Block-scoped variable 'data' used before its declaration. +tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2729: Property 'data' is used before its initialization. tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class 'After' used before its declaration. @@ -8,7 +8,7 @@ tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class ' class X { static illegalBeforeProperty = X.data; ~~~~ -!!! error TS2448: Block-scoped variable 'data' used before its declaration. +!!! error TS2729: Property 'data' is used before its initialization. !!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:7:12: 'data' was declared here. static okBeforeMethod = X.method; @@ -17,7 +17,7 @@ tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class ' !!! error TS2449: Class 'After' used before its declaration. !!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:10:7: 'After' was declared here. ~~~~ -!!! error TS2448: Block-scoped variable 'data' used before its declaration. +!!! error TS2729: Property 'data' is used before its initialization. !!! related TS2728 tests/cases/compiler/scopeCheckStaticInitializer.ts:11:12: 'data' was declared here. static illegal3 = After.method; ~~~~~ diff --git a/tests/baselines/reference/useBeforeDeclaration_propertyAssignment.errors.txt b/tests/baselines/reference/useBeforeDeclaration_propertyAssignment.errors.txt index 0efd967ccc..cf5699de37 100644 --- a/tests/baselines/reference/useBeforeDeclaration_propertyAssignment.errors.txt +++ b/tests/baselines/reference/useBeforeDeclaration_propertyAssignment.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2448: Block-scoped variable 'b' used before its declaration. +tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts(2,27): error TS2729: Property 'b' is used before its initialization. ==== tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts (1 errors) ==== export class C { public a = { b: this.b }; ~ -!!! error TS2448: Block-scoped variable 'b' used before its declaration. +!!! error TS2729: Property 'b' is used before its initialization. !!! related TS2728 tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts:3:13: 'b' was declared here. private b = 0; } diff --git a/tests/baselines/reference/useBeforeDeclaration_superClass.errors.txt b/tests/baselines/reference/useBeforeDeclaration_superClass.errors.txt index b8edc26caf..869812bc0e 100644 --- a/tests/baselines/reference/useBeforeDeclaration_superClass.errors.txt +++ b/tests/baselines/reference/useBeforeDeclaration_superClass.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2448: Block-scoped variable 'x' used before its declaration. +tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2729: Property 'x' is used before its initialization. ==== tests/cases/compiler/useBeforeDeclaration_superClass.ts (1 errors) ==== @@ -28,7 +28,7 @@ tests/cases/compiler/useBeforeDeclaration_superClass.ts(25,18): error TS2448: Bl class J implements I { old_x = this.x; ~ -!!! error TS2448: Block-scoped variable 'x' used before its declaration. +!!! error TS2729: Property 'x' is used before its initialization. !!! related TS2728 tests/cases/compiler/useBeforeDeclaration_superClass.ts:26:5: 'x' was declared here. x = 1; } diff --git a/tests/cases/compiler/forwardRefInClassProperties.ts b/tests/cases/compiler/forwardRefInClassProperties.ts index 80819b1a17..b562f78708 100644 --- a/tests/cases/compiler/forwardRefInClassProperties.ts +++ b/tests/cases/compiler/forwardRefInClassProperties.ts @@ -8,7 +8,7 @@ class Test method() { - let a = b; // Block-scoped variable 'b' used before its declaration + let a = b; // Property 'b' is used before its initialization. let b = 3; } }