Named Tuple elements should allow reserved words as their names #45819
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Bug Report
🔎 Search Terms
tuple elements label reserved word
named tuple elements
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
No errors. As a label it should allow any identifiers, including reserved words.
👩💻 Possible solution
Although
parseTupleElementNameOrTupleElementType
allows any identifier as its name:TypeScript/src/compiler/parser.ts
Line 3559 in 0af2497
before it is invoked, the
isListElement
requires a tuple member start a type:TypeScript/src/compiler/parser.ts
Line 2091 in 0af2497
This is no longer true after we support named tuple member after 4.0, which should start with any valid identifiers / keywords. Because
isListElement
returnsfalse
, the parser does not parse them as tuple elements, which results to confusing parsing errors.We can create a new
ParsingContext
for named tuple members, and returnstoken() === SyntaxKind.CommaToken || tokenIsIdentifierOrKeyword(token())
inisListElement
.The text was updated successfully, but these errors were encountered: