Rename Typescript File

Maybe I'm missing something on this (or maybe I'm too tired: P). In Visual Studio 2012, in a Typescript project, when renaming a ts file instead of renaming the js file associated with that ts file, it creates a new one.

Example:
Old situation: (file1.ts β†’ file1.js) After renaming: (file1337.ts β†’ file.js) + file1337.js // file1337 is not included in the project, I need to do this manually ...

So, is there a way to rename both the ts file and the js directly associated with this file, at the same time, without creating a new one, and manually adding the new js file to the project?

thanks

+6
source share
3 answers

I found that if you delete the associated .js file and any source map (that is, delete the files attached inside the .ts in Solution Explorer), rename the.ts file and then recompile .js files are restored with a new name and are automatically added to project (while the .ts file is already there).

I have to add that I have WebEssentials installed - I don’t know how much of this behavior is related to this, and how much is native to VS.

+5
source

There is a small gap in the Visual Studio extension, which means that renames are not handled perfectly.

The easiest option is to create a new file with the correct name, move the contents, and delete the old file.

A slightly more complicated option is to manually edit the project file after renaming to update the associations.

Using Web Essentials, you have a similar problem with a renamed file with the wrong JavaScript name and a Map file, and you will have to play with it to make it work. It still seems that the cleanest option is to add a new file and transfer the contents, rather than renaming.

+1
source

This is an old question, but in Visual Studio 2015 this problem also exists. At the BuildEvents Pre-build project command line, you can paste the following code:

del /S /Q "$(ProjectDir)\path\to\ts\code\*.js" && del /S /Q "$(ProjectDir)\path\to\ts\code\*.js.map" 

This command will delete all generated .js and .js.map files before building the project.

+1
source

All Articles