Skip to content
Draft
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 internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11452,10 +11452,10 @@ func (c *Checker) checkPropertyAccessibilityAtLocation(location *ast.Node, isSup
if flags&ast.ModifierFlagsAbstract != 0 && c.symbolHasNonMethodDeclaration(prop) && (isThisProperty(location) ||
isThisInitializedObjectBindingExpression(location) ||
ast.IsObjectBindingPattern(location.Parent) && isThisInitializedDeclaration(location.Parent.Parent)) {
declaringClassDeclaration := ast.GetClassLikeDeclarationOfSymbol(c.getParentOfSymbol(prop))
if declaringClassDeclaration != nil && c.isNodeUsedDuringClassInitialization(location) {
parentSymbol := c.getParentOfSymbol(prop)
if parentSymbol != nil && parentSymbol.Flags&ast.SymbolFlagsClass != 0 && c.isNodeUsedDuringClassInitialization(location) {
if errorNode != nil {
c.error(errorNode, diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, c.symbolToString(prop), declaringClassDeclaration.Name().Text())
c.error(errorNode, diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, c.symbolToString(prop), c.symbolToString(parentSymbol))
}
return false
}
Expand Down
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.
};

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))

};

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [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 testdata/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;
};