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

Fix private properties not being allowed in optional chains #60263

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Psychpsyo
Copy link

@Psychpsyo Psychpsyo commented Oct 17, 2024

Fixes #42734

This makes it so that expressions of the form foo?.#bar or foo?.bar.#baz are no longer seen as invalid, since the relevant JavaScript standards allow these by now and TypeScript claims to be a superset of JavaScript.
Specifically, private properties are now allowed inside an optional chain.
This syntax is allowed since tc39/proposal-class-fields#301

The added this.a = this; in privateIdentifierChain.1.ts is there so that line 14, this?.a.#b;, does not error because a might be undefined, as that's not what this file is testing for.

I'm sorry for fixing an issue that is not in the backlog, but this is bothering me personally and has existed for years at this point.
Otherwise, I have verified that:

  • Code is up-to-date with the main branch
  • You've successfully run hereby runtests locally
  • There are new or updated unit tests validating the change

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Oct 17, 2024
@Psychpsyo
Copy link
Author

@microsoft-github-policy-service agree

@Psychpsyo Psychpsyo changed the title Fix private properties not ebing allowed in optional chains Fix private properties not being allowed in optional chains Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

TS18030: An optional chain cannot contain private identifiers
3 participants