Skip to content

An accessibility modifier cannot be used with a private identifier #44870

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
jonlepage opened this issue Jul 2, 2021 · 5 comments
Closed

An accessibility modifier cannot be used with a private identifier #44870

jonlepage opened this issue Jul 2, 2021 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jonlepage
Copy link

jonlepage commented Jul 2, 2021

Suggestion

i think ts should allow the modifier private on a private identifier.
for keep a kind of design correlation in a project.

Actually change a public identifier to #private , lint error on all ts private modifier
image

Is there a way to ignore this error in tsconfigu ?

export class A  {
	private #foo= new foo();
}

i color all my accessibility modifier for fast nav, but private identifier lint error with the private accessibility modifier !

🔍 Search Terms

An accessibility modifier cannot be used with a private identifier

@sandersn sandersn added Suggestion An idea for TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug and removed Suggestion An idea for TypeScript labels Jul 2, 2021
@sandersn
Copy link
Member

sandersn commented Jul 2, 2021

#private and private are mutually exclusive, like public and private. Typescript doesn't allow combining those either. It's confusing because they do nearly the same thing, but that's even more reason to keep them separate.

@jonlepage
Copy link
Author

jonlepage commented Jul 2, 2021

#private and private are mutually exclusive, like public and private. Typescript doesn't allow combining those either. It's confusing because they do nearly the same thing, but that's even more reason to keep them separate.

ho oki, i will take a look on doc to understand more !
thanks for your fast answer and your reason to keep this separate , i will close !

@revolter
Copy link

like public and private

Not quite, since they're not opposites.

they do nearly the same thing

Not that nearly, since private is enforced at compile time, and #private is enforced at runtime: https://stackoverflow.com/a/59641565/865175.

@ctsstc
Copy link

ctsstc commented May 9, 2025

I wanted to know if this transpiles down to a #privateProperty I guess it does not unfortunately even with the target of esNext.

I know there's deep history here. The private keyword has been utilized by TypeScript well before JavaScript even had private properties or even classes. I would expect if the TSConfig target was modern enough that it should be transpiling private into a #privateProperty. But then we would need to make sure there wasn't any conflict. It seems that if we have the language feature now and have the runtime safety of OOP private access that it should be utilized. It makes me wonder if older transpilation targets have never isolated the values, or if that was lost in the transition to classes?

If we look at the ES3 target transpilation, we'll see that transpilation did indeed protect it's scope a bit more it seems by abstracting it out into a variable. This would just depend what context this was then ran it, but it wouldn't expose the property on the class instance.

@RyanCavanaugh
Copy link
Member

@ctsstc see #31670

ctsstc added a commit to deschutes-tech-guild/coupon-clicker that referenced this issue May 14, 2025
I did my deep dig on this; Im not sure how I feel about it exactly...
<microsoft/TypeScript#44870 (comment)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants