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

No TSC error for duplicate dynamic keys with static readonly values #26318

Closed
tompere opened this issue Aug 9, 2018 · 4 comments
Closed

No TSC error for duplicate dynamic keys with static readonly values #26318

tompere opened this issue Aug 9, 2018 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@tompere
Copy link

tompere commented Aug 9, 2018

TypeScript Version: 3.1.0-dev.20180809

Search Terms: dynamic key duplicate identifier

Code

const X = 'x'

enum Y {
  ONE = 'one',
  TWO = 'one'
}

// static key - 'duplicate identifier' error

const obj1 = {
  'y': 'wham',
  'y': 'bam' // as expected, tsc error `Duplicate identifier ''y''`
}

const obj2 = {
  y: 'wham',
  y: 'bam' // as expected, tsc error `Duplicate identifier 'y'`
}

// [the bug] dynamic key - no 'duplicate identifier' error

const obj3 = {
  [X]: 'wham',
  [X]: 'bam' // no tsc error!
}

const obj4 = {
  [Y.ONE]: 'wham',
  [Y.TWO]: 'bam' // no tsc error!
}

Expected behavior:
When assigning duplicate dynamic keys to plain objects, which can be statically inferred (e.g. enums or const with primitive type) - tsc should show a compilation error.

Actual behavior:
no compilation error.

Playground Link:
a long long long playground link ...

Related Issues: N/A

@AlCalzone
Copy link
Contributor

Why should this be an error?

enum Y {
    ONE = 'one',
    TWO = 'two'
}

const obj4 = {
    [Y.ONE]: 'wham',
    [Y.TWO]: 'bam' // no tsc error!
}

@tompere
Copy link
Author

tompere commented Aug 9, 2018

@AlCalzone you're right.
updated:

enum Y {
    ONE = 'one',
    TWO = 'one'
}

@ajafff
Copy link
Contributor

ajafff commented Aug 9, 2018

Duplicate of #25758

@ghost ghost added the Duplicate An existing issue was already created label Aug 9, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants