Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34449,10 +34449,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
(flags & ModifierFlags.Abstract) && symbolHasNonMethodDeclaration(prop) &&
(isThisProperty(location) || isThisInitializedObjectBindingExpression(location) || isObjectBindingPattern(location.parent) && isThisInitializedDeclaration(location.parent.parent))
) {
const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)!);
if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(location)) {
const parentSymbol = getParentOfSymbol(prop);
if (parentSymbol && parentSymbol.flags & SymbolFlags.Class && isNodeUsedDuringClassInitialization(location)) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces around the bitwise AND operator. The pattern should be parentSymbol.flags & SymbolFlags.Class with spaces on both sides of the & operator to match the codebase style.

Copilot uses AI. Check for mistakes.
if (errorNode) {
error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), getTextOfIdentifierOrLiteral(declaringClassDeclaration.name!));
error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), symbolToString(parentSymbol));
}
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/errorInUnnamedClassExpression.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
errorInUnnamedClassExpression.ts(5,14): error TS2715: Abstract property 'bar' in class 'Foo' cannot be accessed in the constructor.
errorInUnnamedClassExpression.ts(7,5): error TS1253: Abstract properties can only appear within an abstract class.
errorInUnnamedClassExpression.ts(7,14): error TS7008: Member 'bar' implicitly has an 'any' type.


==== errorInUnnamedClassExpression.ts (3 errors) ====
// https://github.com/microsoft/TypeScript/issues/62920

let Foo = class {
constructor() {
this.bar++;
~~~
!!! error TS2715: Abstract property 'bar' in class 'Foo' cannot be accessed in the constructor.
}
abstract bar;
~~~~~~~~
!!! error TS1253: Abstract properties can only appear within an abstract class.
~~~
!!! error TS7008: Member 'bar' implicitly has an 'any' type.
};

19 changes: 19 additions & 0 deletions tests/baselines/reference/errorInUnnamedClassExpression.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/errorInUnnamedClassExpression.ts] ////

=== errorInUnnamedClassExpression.ts ===
// https://github.com/microsoft/TypeScript/issues/62920

let Foo = class {
>Foo : Symbol(Foo, Decl(errorInUnnamedClassExpression.ts, 2, 3))

constructor() {
this.bar++;
>this.bar : Symbol(Foo.bar, Decl(errorInUnnamedClassExpression.ts, 5, 5))
>this : Symbol(Foo, Decl(errorInUnnamedClassExpression.ts, 2, 9))
>bar : Symbol(Foo.bar, Decl(errorInUnnamedClassExpression.ts, 5, 5))
}
abstract bar;
>bar : Symbol(Foo.bar, Decl(errorInUnnamedClassExpression.ts, 5, 5))

};

28 changes: 28 additions & 0 deletions tests/baselines/reference/errorInUnnamedClassExpression.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/errorInUnnamedClassExpression.ts] ////

=== errorInUnnamedClassExpression.ts ===
// https://github.com/microsoft/TypeScript/issues/62920

let Foo = class {
>Foo : typeof Foo
> : ^^^^^^^^^^
>class { constructor() { this.bar++; } abstract bar;} : typeof Foo
> : ^^^^^^^^^^

constructor() {
this.bar++;
>this.bar++ : number
> : ^^^^^^
>this.bar : any
> : ^^^
>this : this
> : ^^^^
>bar : any
> : ^^^
}
abstract bar;
>bar : any
> : ^^^

};

11 changes: 11 additions & 0 deletions tests/cases/compiler/errorInUnnamedClassExpression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/62920

let Foo = class {
constructor() {
this.bar++;
}
abstract bar;
};