Skip to content

Duplicate identifier 'X'

Error message

                Duplicate identifier
              

Quick summary

You declared two variables, functions, types, or interfaces with the same name in the same scope. TypeScript does not allow duplicate identifiers (except for interface merging).

Why this happens

  • Declaring two variables with the same name in the same scope

  • Importing two different things with the same name

  • A function and a type with the same name (without overloading)

  • Merge conflicts bringing in duplicate declarations

Minimal example

✗ Broken code
const name = "Alice";
const name = "Bob"; // duplicate
✓ Fixed code
const firstName = "Alice";
const lastName = "Bob";

Rename one of the variables to avoid the duplicate identifier.

How to diagnose

  • Search for all declarations of the name in the file

  • Check imports for naming conflicts

  • Look for declarations in included files (especially .d.ts)

How to fix

  • Rename one of the declarations

  • Use import aliases: import { X as Y }

  • Remove the duplicate declaration

  • For interfaces, use declaration merging intentionally

How to prevent

  • Use consistent naming conventions

  • Use import aliases to avoid naming conflicts

  • Run ESLint with no-dupe-class-members rule

Related Resources

Related Glossary

← Back to language