- Error
- Reported by the binder
TS2300
Duplicate identifier '{0}'.
The same name is declared twice in one scope in a way that can't merge, such as two properties or two classes. Rename or remove one.
What it means
Some declarations can merge (interfaces with interfaces, namespaces with classes). Others can't, and declaring the same name twice in the same scope is reported at each declaration: two classes, two type aliases, two members with the same name in an interface or class.
Example
export interface User {
id: string;
id: string;
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,3): error TS2300: Duplicate identifier 'id'.
index.ts(3,3): error TS2300: Duplicate identifier 'id'.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Remove or rename one declaration.
- For block-scoped variables (
let/const) the error is TS2451 instead.