Skip to content

Some private identifier errors are duplicated and uninformative #46824

Closed
@sandersn

Description

@sandersn

From privateNameInInExpression.errors.txt:

            const b = #fiel in v; // Bad - typo in privateID
                      ~~~~~
!!! error TS2304: Cannot find name '#fiel'.
                      ~~~~~
!!! error TS2339: Property '#fiel' does not exist on type 'any'.
            for (#field in v) { /**/ } // Bad - 'in' not allowed
                 ~~~~~~
!!! 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
                 ~~~~~~
!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access.

Expected: One error on each line of code: "Cannot find name '#fiel'" and "The left-hand side of a 'for...in' statement must be a variable or property access."
Actual: Two errors on each line.

The cause is that checkGrammarPrivateIdentifierExpression does not check whether other errors might apply. From my most recent read of it, I think only the first error is actually valuable, and that the "Cannot find name '#fiel'" error can be issued elsewhere. It's not really a grammatical error in any case -- it's likely just issued there because the ES spec refers to these errors as syntactic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions