Duplicate identifier
An identifier, such as a variable, function, or class name, has been declared more than once in the same scope.
- 1Declaring the same variable twice using 'let' or 'const' in the same block.
- 2Defining two functions with the same name in the same scope.
- 3A class and a function in the same scope share the same name.
Two variables with the same name are declared in the same scope.
const name = "Alice"; const name = "Bob";
expected output
error TS2300: Duplicate identifier 'name'.
Fix 1
Rename the identifier
WHEN The identifiers are intended to be distinct.
const user = "Alice"; const admin = "Bob";
Why this works
Using unique names for each identifier resolves the conflict.
Fix 2
Reassign the variable
WHEN The intent is to change the value of an existing variable.
let name = "Alice"; name = "Bob";
Why this works
Using 'let' allows reassignment without redeclaring the variable.
✕ Use 'var' to allow re-declaration
This behavior is often a source of bugs and is disallowed in strict mode.
microsoft/TypeScript src/compiler/diagnosticMessages.json
MDN: Redeclaring variables ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev