Skip to content

objectKeyDuplicates

Reports unnecessary duplicate keys that override previous values.

✅ This rule is included in the ts untyped presets.

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.

const
const object: {
a: number;
}
object
= {
a: number
a
: 1, a: 2 };
Error ts(1117) ― An object literal cannot have multiple properties with the same name.
const
const config: {
port: number;
host: string;
}
config
= {
port: number
port
: 3000,
host: string
host
: "localhost",
port: 8080,
Error ts(1117) ― An object literal cannot have multiple properties with the same name.
};

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.