Skip to content

fix(60617): abstract modifier cannot be used with private a identifier #60627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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