# no-dupe-keys

> Disallow two keys with the same name in an object literal

When an object literal has the same key twice, the last value silently replaces the first. In a long object it's easy to add a key that's already there, and then one of the two has no effect.

A getter and a setter with the same name are a pair, so they're allowed.

This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-dupe-keys" = "off" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
const options = {
  timeout: 1000,
  retries: 3,
  timeout: 5000,
};
```

Not reported:

{/* good */}
```js
const options = {
  timeout: 5000,
  retries: 3,
};
```

Keys are compared by value, so `"timeout"` is the same key as `timeout`, and `0x1` is the same key as `1`:

{/* bad {"count": 2} */}
```js
const options = {
  timeout: 1000,
  "timeout": 5000,
};

const labels = {
  1: "one",
  0x1: "uno",
};
```

A computed key such as `[name]` and a spread aren't compared, because their keys are only known at runtime:

{/* good */}
```js
const options = {
  timeout: 1000,
  [name]: 5000,
  ...overrides,
};
```
