Skip to content

fix(46824): remove duplicate private identifier errors #47116

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

Conversation

Andrewnt219
Copy link
Contributor

@Andrewnt219 Andrewnt219 commented Dec 12, 2021

Fixes #46824

Description

Base on the suggestions in #46824, these two errors should not be reported if the private identifier is used inside a for...in

"error TS2304: Cannot find name '#fiel'."

"error TS1451: Private identifiers are only allowed in class bodies and may only be used as part of a class member declaration, property access, or on the left-hand-side of an 'in' expression"

For TS2304, an additional check is it also should not be reported if the private identifier is used with in operator.

In the issue, @sandersn suggests

Cannot find name '#fiel'.

should only check for in operator and getSymbolForPrivateIdentifierExpression. But if I don't check for the for...in as well, it will show like this

for (#field in v) { /**/ } // Bad - 'in' not allowed

error TS2304: Cannot find name '#field'.
error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access.

Tests

Failling tests:

  • tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 12, 2021
@sandersn
Copy link
Member

The code looks good, but can you gulp baseline-accept and add that in a commit?

@Andrewnt219 Andrewnt219 force-pushed the 46824-remove-dupliate-private-identifier-errors branch from 43a65aa to 7aa2e82 Compare December 16, 2021 00:51
@Andrewnt219 Andrewnt219 force-pushed the 46824-remove-dupliate-private-identifier-errors branch from 7aa2e82 to e8833fe Compare December 16, 2021 01:40
@Andrewnt219
Copy link
Contributor Author

@sandersn my bad, I didn't know I have to runtests first. Should be good now.

@Andrewnt219 Andrewnt219 requested a review from sandersn December 16, 2021 01:41
@sandersn sandersn merged commit 270b0d1 into microsoft:main Dec 16, 2021
mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some private identifier errors are duplicated and uninformative
3 participants