且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在同一Visual Studio项目中混合使用Node.js和Typescript?

更新时间:2022-06-13 22:20:38

是的,可以,但是有点尴尬(我希望Node.js工具将来会更好地支持此功能).

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

您应该创建Node.js项目并添加一个新文件.选择新的文本文件,然后输入扩展名为.ts的文件.它将创建一个打字稿文件.

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.

这时,您将拥有一个没有编译的javascript的打字稿文件.

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

要解决此问题,请转到VS工具"菜单,打开选项",然后转到文本编辑器">"TypeScript">项目",然后在保存时编译"下选中自动编译不包含在其中的TypeScript文件"项目,然后选择使用commonjs ...".

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...".

之后,打开每个.ts文件并保存-tsc会将其编译为javascript.

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

该解决方案的缺点是您必须记住手动保存每个编辑的.ts,但是我认为这没什么大不了的.

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.

以下是该帖子的链接,该帖子帮助我解决了相同的问题: http://blog.ctaggart.com/2013/11/nodejs-tools-with-typescript-console-app.html

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

更新

如果您使用Node.js工具的最新开发版本,则会看到已添加TypeScript支持.您可以创建TypeScript项目(其中包括调试.ts文件的功能)

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