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

About # and 'private'. Why not '#private' ? #60275

Closed
1 task done
mberdev opened this issue Oct 18, 2024 · 2 comments
Closed
1 task done

About # and 'private'. Why not '#private' ? #60275

mberdev opened this issue Oct 18, 2024 · 2 comments
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@mberdev
Copy link

mberdev commented Oct 18, 2024

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

I was thinking about this topic : #31670

The conversation can go on.

The facts :

  • private is a Typescript keyword
  • private field does not get transpiled into #field or any constraining code, as per Typescript philosophy.
  • # is Javascript syntax.
  • # is considered awkward by many Typescript devs, because:
    • it's carried around alongside the variable name.
    • it's stealing the spot of what private would be used for in the vast majority of OOP languages.

There's got to be a way of getting the best of both.

What do you think of this ?

  • A new typescript keyword, '#private'
  • It gets transpiled into a #field
  • Example : #private field: number. Then in Typescript it's used normally: this.field = 12;. In Javascript it's compiled as this.#field = 12;
@jcalz
Copy link
Contributor

jcalz commented Oct 18, 2024

This proposal would require type-directed emit as described in the issue you linked and will therefore not happen. TS cannot sometimes emit x.y as x.#y depending on what x is.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Out of Scope This idea sits outside of the TypeScript language design constraints labels Oct 18, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Out of Scope" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants