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

Named Tuple elements should allow reserved words as their names #45819

Open
JLHwung opened this issue Sep 10, 2021 · 0 comments
Open

Named Tuple elements should allow reserved words as their names #45819

JLHwung opened this issue Sep 10, 2021 · 0 comments
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

Comments

@JLHwung
Copy link

JLHwung commented Sep 10, 2021

Bug Report

🔎 Search Terms

tuple elements label reserved word
named tuple elements

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common "Bugs" That Aren't Bugs"

⏯ Playground Link

Playground link with relevant code

💻 Code

type x = [if: any]
// but some keywords are allowed, e.g.
type y = [void: any]

🙁 Actual behavior

Unused label.
'any' only refers to a type, but is being used as a value here.
Type expected.
'(' expected.
Unexpected keyword or identifier.
Declaration or statement expected.

🙂 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:

const name = parseIdentifierName();

before it is invoked, the isListElement requires a tuple member start a type:

return token() === SyntaxKind.CommaToken || isStartOfType();

This is no longer true after we support named tuple member after 4.0, which should start with any valid identifiers / keywords. Because isListElement returns false, 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 returns token() === SyntaxKind.CommaToken || tokenIsIdentifierOrKeyword(token()) in isListElement.

@andrewbranch andrewbranch added 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 labels Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants