Closed
Description
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.