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

1

8

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?

Accordingly answered 9/1, 2014 at 16:18 Comment(0)
S
11

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

Stylize answered 5/2, 2014 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.