Duplicate identifier error messages in Visual Studio projects when TypeScript files are moved from one location to another in Solution Explorer

Posted: (EET/GMT+2)

 

For JavaScript related work, I'm using the TypeScript language mostly. When your ASP.NET projects grow, you will sooner or later run into the situation where you want to move files around in your projects. For example, you might want to group related TypeScript files into their own folders, etc.

However, there's a problem in Visual Studio 2015 regarding this rearrangement: if you move a TypeScript .ts file in the Solution Explorer to a new location (another folder or sub-folder), intermediate and/or compiled output files are not cleared.

This results in compiler errors with the message:

Duplicate identifier “XXX”

These errors are reported because Visual Studio will still find the compiled .js (JavaScript output files) from their original locations, and thus will complain about duplicate identifiers.

The solution to this problem is to open the File Explorer, and delete the intermediate and/or output files from their original locations. Thus, if you had moved the file "MyCode.ts", you would need to delete the files "MyCode.js" and "MyCode.map" from their original locations. You could also try Visual Studio's Build/Clean command, too.

Hope this helps!