Skip to content

Wrong this.propertyName reference inside abstract method realization #7724

Closed
@sanex3339

Description

@sanex3339

TypeScript Version:

1.8.9 / nightly
Code

abstract class Abstract {
  protected name: string;

  constructor () {
    this.abstractMethod();
  }

  protected abstract abstractMethod (): void;
}

class Concrete extends Abstract {
  protected name: string = 'Concrete';

  protected abstractMethod () {
    console.log(this, this.name); // Concrete, undefined
  }
}

new Concrete();

Playground: link

Expected behavior:
this.name inside abstractMethod() realization must be pointed at name property of Concrete class.

Actual behavior:
this.name inside abstractMethod() realization is pointed at name property of Abstract class.

Metadata

Metadata

Assignees

Labels

By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions