Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17478,7 +17478,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 &&
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5419,6 +5419,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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) ====
Expand All @@ -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 = () => { }
}
Original file line number Diff line number Diff line change
@@ -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) ====
Expand All @@ -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.
}

Expand Down
10 changes: 5 additions & 5 deletions tests/baselines/reference/forwardRefInClassProperties.errors.txt
Original file line number Diff line number Diff line change
@@ -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.


Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/forwardRefInClassProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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.


==== tests/cases/compiler/scopeCheckStaticInitializer.ts (4 errors) ====
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;

Expand All @@ -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;
~~~~~
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) ====
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/compiler/forwardRefInClassProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}