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

Private(set) keyword #46029

Closed
5 tasks done
FilipeBeck opened this issue Sep 23, 2021 · 2 comments
Closed
5 tasks done

Private(set) keyword #46029

FilipeBeck opened this issue Sep 23, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@FilipeBeck
Copy link

Suggestion

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

A keyword (private(set), maybe) to allow fields that are public for reading and private for writing.

Workaround:

class MyClass {
  public readonly privateSetProp: number

  someMethod() {
    (this.privateSetProp as any) = 10
  }
}
@MartinJohns
Copy link
Contributor

MartinJohns commented Sep 23, 2021

Duplicate of #37487. Used search terms: private public in:title. What search terms did you use?

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Sep 23, 2021
@FilipeBeck
Copy link
Author

I used private set. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants