elseIfDuplicates
Reports duplicate conditions in if-else-if chains that make code unreachable.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
When an if-else-if chain contains duplicate conditions, the branch with the duplicate condition will never execute. This is because the earlier identical condition will always be evaluated first and match when true, preventing the duplicate condition from ever being reached. Duplicate conditions typically indicate a copy-paste error or a logic mistake in the code.
Examples
Section titled “Examples”if (const status: string
status === "pending") { const handlePending: () => void
handlePending();} else if (const status: string
status === "active") { const handleActive: () => void
handleActive();} else if (const status: string
status === "pending") { const handlePendingAgain: () => void
handlePendingAgain();}if (const isValid: boolean
isValid && const isActive: boolean
isActive) { const processValid: () => void
processValid();} else if (const isPending: boolean
isPending) { const processPending: () => void
processPending();} else if (const isValid: boolean
isValid && const isActive: boolean
isActive) { const processValidAgain: () => void
processValidAgain();}if (const count: number
count === 1) { const handleOne: () => void
handleOne();} else if (const count: number
count === 2) { const handleTwo: () => void
handleTwo();} else if (const count: number
count === 1) { const handleOneAgain: () => void
handleOneAgain();}if (const status: string
status === "pending") { const handlePending: () => void
handlePending();} else if (const status: string
status === "active") { const handleActive: () => void
handleActive();} else if (const status: string
status === "completed") { const handleCompleted: () => void
handleCompleted();}if (const isValid: boolean
isValid && const isActive: boolean
isActive) { const processValid: () => void
processValid();} else if (const isPending: boolean
isPending) { const processPending: () => void
processPending();} else if (const isValid: boolean
isValid && !const isActive: boolean
isActive) { const processInactive: () => void
processInactive();}if (const count: number
count === 1) { const handleOne: () => void
handleOne();} else if (const count: number
count === 2) { const handleTwo: () => void
handleTwo();} else if (const count: number
count === 3) { const handleThree: () => void
handleThree();}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 uses patterns that look like duplicate conditions but actually modify state behind-the-scenes, you might not want to enable this rule.
For example, projects that modify state in computed object get() properties or use Proxy are often considered overly difficult to reason about for both humans and lint rules.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noDuplicateElseIf - ESLint:
no-dupe-else-if - Oxlint:
eslint/no-dupe-else-if