How to mix Node.js and Typescript in the same Visual Studio project?

Visual Studio has a Typescript addon for developing apps with the Typescript language.

And there is also the Node.js Tools for VS, with which one is able to create and debug Node.js applications.

I tried creating a Node.js project, but then I couldn’t add Typescript files to it, and if I added them by hand, they did not get compiled to javascript (couldn’t set their Build action to TypeScriptCompile.)
And if I create a simple Typescript project, then it does not start my app with Node, because it is basically just an ASP.Net web project.

Is it possible to somehow create a VS project that uses Typescript and Node.js integration at the same time?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Yes, it is possible, but in a somewhat awkward way (I hope Node.js Tools will support this better in the future).

You should create Node.js project and add a new file. Choose new text file and enter its name with .ts extension. It will create a typescript file.

At this point you will have a typescript files without compiled javascript.

To fix this go to VS “Tools” menu, open “Options” and go to “Text editor” > “TypeScript” > “Project” and under “Compile on Save” check “Automatically compile TypeScript files which are not part of a project and choose “Use commonjs…”.

After that open each .ts file and save it – tsc will compile it to javascript.

Downside of this solution is that you have to remember to save manually each .ts you edit, but I think its not a big deal.

Here’s a link to the post that helped me with the same problem: http://blog.ctaggart.com/2013/11/nodejs-tools-with-typescript-console-app.html

Update

If you grab the latest dev build of Node.js Tools you will see that TypeScript support is added. you can create TypeScript project (and this includes debugging .ts files feature)

https://nodejstools.codeplex.com/discussions/531222

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply