Skip to content

Allows private property access without warnings #59888

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
leanderpaul opened this issue Sep 7, 2024 · 1 comment
Closed

Allows private property access without warnings #59888

leanderpaul opened this issue Sep 7, 2024 · 1 comment

Comments

@leanderpaul
Copy link

leanderpaul commented Sep 7, 2024

πŸ”Ž Search Terms

private properties public access, private properties

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this but have not found any answers.

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&jsx=0&ts=3.3.3#code/MYGwhgzhAEAiCmBbA9tA3gKGtADgJwEsA3MAF3mgPMWgF5oByfYs+Bgbi2gjERxAr0AjJwC+GDMGQA7CKWgATJKnrT4AdzjKAFAEpOU2cgEA6EMgDm2pSgDaDKkgYBdXRhvITjxEA

πŸ’» Code

class Demo {
  private item = 'private';
  sample = 1;
}

const demo = new Demo();
console.log(demo['item'])
demo.item

πŸ™ Actual behavior

I am able to access the item property without the typescript throwing any errors. This property is a private property so typescript is supposed to throw an error like Property 'item' is private and only accessible within class 'Demo'.

πŸ™‚ Expected behavior

The typescript should throw an error Property 'item' is private and only accessible within class 'Demo'.

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

This is working as intended. Duplicate of #26328.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants