Wednesday, January 2, 2013

Converting existing JavaScript code to TypeScript in Visual Studio

The best way to learn new technology is to start using it with real project. I have such - IZWebFileManager. It  was written when ASP.NET MVC wasn't event in mind and Web Forms was only framework for web application in .NET.  IZWebFileManager is an ASP.NET Server Control and has about 1300 lines of JavaScript code.

The challenge is to convert all existing JavaScript code in the project to TypeScript. The result of this effort you can find here: https://github.com/manishma/IZWebFileManager/tree/typescript

It this post I'll tell you about steps I went through.


Tuesday, January 1, 2013

Using TypeScript with an existing ASP.NET project.

TypeScript looks very powerful for me, and I want to use it with all my ASP.NET projects. But I found it is not trivial to add support of TypeScript to an existing project. After installing TypeScript for Visual Studio 2012 I was able to add new TypeScript file (*.ts) to the project, but any changes in the *.ts file did not affect it's output *.js file. Seemed like TypeScript compiler doesn't work for me. It was strange, because I found it works perfect in test project created from TypeScriptHTMLApp template.

After comparing *.cspoj files I found the difference - there is an "magic" build step has done to compile *.ts files in TypeScriptHTMLApp template:




I just added this lines in my existing project's *.csproj file and it works fine now.

Later I found the same answer in Stack Overflow. (Should I've searched there for an answer first? :))