Skip to content
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

Support ES Private Methods in TypeScript #5258

Closed
kitsonk opened this issue May 13, 2020 · 4 comments
Closed

Support ES Private Methods in TypeScript #5258

kitsonk opened this issue May 13, 2020 · 4 comments
Labels
bug Something isn't working correctly fix available there is a fix available in a third party library that needs to be merged upstream Changes in upstream are required to solve these issues
Milestone

Comments

@kitsonk
Copy link
Contributor

kitsonk commented May 13, 2020

Currently we support both private fields (#foo = "bar") and private methods (#foo() {}) in the version of v8 we use in Deno. So the following is valid in JavaScript:

class Foo {
  #foo() {
    console.log("bar");
  }
  bar() {
    this.#foo();
  }
}

The problem is that while private fields are allowed in TypeScript, private methods are not currently allowed. This was because private fields and private methods were two seperate proposals and private methods took longer to reach Stage 3.

We have been working around this by setting an arrow function as the initialiser for a private field, but that is actually sub-optimal as these are not "static" as part of the classes prototype and are initialised on every construction of an instance.

This is a tracking issue for microsoft/TypeScript#37677 which deals with ES private methods in TypeScript.

@bartlomieju bartlomieju added the upstream Changes in upstream are required to solve these issues label May 21, 2020
@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 6, 2021
@kitsonk kitsonk added the bug Something isn't working correctly label Jan 7, 2021
@stale stale bot removed the stale label Jan 7, 2021
@kitsonk
Copy link
Contributor Author

kitsonk commented Mar 25, 2021

This has finally landed upstream and will be in TS 4.3. 🎉

@kitsonk kitsonk added the fix available there is a fix available in a third party library that needs to be merged label Mar 25, 2021
@kitsonk kitsonk added this to the 1.11.0 milestone Mar 25, 2021
@satyarohith
Copy link
Member

Related #9960

@bartlomieju
Copy link
Member

TypeScript 4.3 landed in #9960, so closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly fix available there is a fix available in a third party library that needs to be merged upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

3 participants