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

Duplicate object keys not caught when using variables #43186

Closed
skylerjokiel opened this issue Mar 10, 2021 · 0 comments · Fixed by #49848
Closed

Duplicate object keys not caught when using variables #43186

skylerjokiel opened this issue Mar 10, 2021 · 0 comments · Fixed by #49848
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@skylerjokiel
Copy link

Bug Report

🔎 Search Terms

duplicate string identifiers
duplicate keys in object

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about duplicate/keys/properties
  • In the playground 3.3.3 doesn't have any support for duplicate keys and 3.5.1 has support for ids but this bug exists

⏯ Playground Link

Playground link with relevant code

💻 Code

const bar = "bar";

const a = {
    ["foo"]: 1,
    ["foo"]: 2, // Error
    [bar]: 3,
    [bar]: 4, // Not Error
};

🙁 Actual behavior

The second instance of bar is allowed.

🙂 Expected behavior

The second instance of bar as an input should not be allowed.

Additional

When you introduce bar as a key in any other form it causes the error I would expect with just the variables.

Playground link to this scenario

const bar = "bar";

const a = {
    ["foo"]: 1,
    ["foo"]: 2, // Error
    [bar]: 3,
    [bar]: 4, // Error
    bar: 5, // Error
};
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 11, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 11, 2021
@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants