Skip to content

Conversation

@a-tarasyuk
Copy link
Contributor

Fixes #60617

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Nov 27, 2024
@whzx5byb
Copy link

abstract class A {
    abstract #x: number;
    getX() {
        return this.#x;
    }
}

will be compiled to

class A {
    getX() {
        return this.#x;
    }
}

and throw a runtime error because an abstract member will be erased.

@a-tarasyuk a-tarasyuk marked this pull request as draft November 27, 2024 17:19
Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

This needs the corresponding emit change (and test) to preserve #x; when we're seeing abstract #x;

@whzx5byb
Copy link

@RyanCavanaugh I don't think it's a good idea. Even if we preserve #x, the private property is still not "implementable", for example this code:

abstract class A {
  abstract #x: number;

  getX() {
    return this.#x;
  }

  static B = class B extends A {
    #x = 5;
  };
}

will be compiled to (if we preseve #x):

class A {
  #x;

  getX() {
    return this.#x;
  }

  static B = class B extends A {
    #x = 5;
  };
}

and if you call new A.B().getX() you will only get undefined, which is not the desired value.

@RyanCavanaugh
Copy link
Member

@whzx5byb good point - retagging the original issue

@a-tarasyuk a-tarasyuk closed this Nov 27, 2024
@a-tarasyuk a-tarasyuk deleted the fix/60617 branch November 29, 2024 12:41
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

abstract modifier cannot be used with private a identifier

5 participants