Skip to content

Duplicated object key in const not detected when the key is a number preceded by - or + #38295

Closed
@rigwild

Description

@rigwild

TypeScript Version: 3.9.0-dev.20200422

Search Terms:

  • Signed numbers
  • Object keys negative
  • readonly negative key
  • object key negative
  • object key duplicate
  • as const negative
  • object key operand
  • others...

Code

export const rotate = {
  "-45": "test",
  [-45]: "test" // Duplicate NOT detected
};

export const rotate2 = {
  "45": "test",
  [+45]: "test" // Duplicate NOT detected
};

export const rotate4 = {
  "45": "test",
  [45]: "test" // Duplicate detected
};

Expected behavior:
TypeScript should alert the user that there's a duplicated key.

Actual behavior:
Key duplication is not detected when the key is a number preceded by - or +.

Playground Link

Related Issues:
#37866 #38133 #37292

The bug seems to be there for a very long time (it has the same behavior on v2.4.1 on the playground).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions