objectKeyDuplicates
Reports unnecessary duplicate keys that override previous values.
✅ This rule is included in the ts untyped preset.
Duplicate object keys are legal in JavaScript, but they can lead to unexpected behavior. When duplicate keys exist, only the last value for a given key is used. This can cause confusion and bugs, especially when maintaining the code.
Examples
Section titled “Examples”const object = { a: 1, a: 2 };
const config = { port: 3000, host: "localhost", port: 8080,};const object = { a: 1, b: 2 };
const config = { host: "localhost", port: 8080,};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your project intentionally creates duplicate keys as an unusual style choice, this rule may not be for you. If you have a rare case where duplicate keys are intentional, you can use Flint disable comments for those specific situations instead of completely disabling this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noDuplicateObjectKeys - ESLint:
no-dupe-keys
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.