Skip to content

Add support for ES.Next private methods and private accessor properties #39066

Closed
@PetaSoft

Description

@PetaSoft

Search Terms

TypeScript 3.9, TC39, Stage 3, ES.Next, private methods, private accessor properties, #methods

Suggestion

Private methods and private accessor properties (both static and instance) are currently at stage 3 of the TC39 working group. They will hopefully be part of the ES2021 standard. The Google Javascript V8 engine in Version 8.3 and Node.js 13.2+ support these features already if one uses the flag --harmony-private-methods. Google Chrome 84, and Google Javascript V8 8.4 engine will support them officially (see compatibility table). Node.js will probably follow soon after the Google Chome 84 release.

Use Cases

TC39 private methods and private accessor properties offer standard compatibility with future Javascript versions.

Examples

class newFeatures {
  static #classMethod(): void {   }
  static get #classPropertyAccessor(): number { return 0; }
  static set #classPropertyAccessor(v: number): void {   }
  #instanceMethod(): void {   }
  get #instancePropertyAccessor(): number { return 0; }
  set #instancePropertyAccessor(v: number): void {   }
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions