TS2393

error TS2393: Duplicate function implementation.

Broken Code ❌

1
2
3
function add(a: number, b: number) {
return a + b;
}

Fixed Code ✔️

This error may occur when you have multiple files within the same project that implement the same function with the same name. To resolve this issue, you need to configure TypeScript to recognize a file as a script rather than a module. This can be achieved by setting the “moduleDetection” option to “force” instead of the default “auto”:

tsconfig.json
1
2
3
4
5
{
"compilerOptions": {
"moduleDetection": "force"
}
}