对Visual Studio 2017的打字稿支持 [英] Typescript Support for Visual Studio 2017

查看:102
本文介绍了对Visual Studio 2017的打字稿支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在尝试学习TypeScript,在使用.ts文件安装"Web Essentials"扩展名后,我一直在观看一些视频,Visual Studio为您提供了一个预览面板,以便您可以看到您键入的JavaScript.

I have recently been trying to learn TypeScript, and in some of the videos I have been watching after installing the 'Web Essentials' extension when working with a .ts file visual studio gives you a pre-view panel so you can see the JavaScript as you type.

这些视频似乎正在使用VS 2012.

These videos seem to be using VS 2012.

但是,在VS 2017上安装Web Essentials似乎没有此选项,有人知道我如何才能在VS 2017中使用它吗?它对TypeScript是否具有相同的支持?

However installing Web Essentials on VS 2017 doesn't seem to have this option, does anyone know how I can get this to work in VS 2017? Does it have the same support for TypeScript?

推荐答案

因此,默认情况下,VS2017中安装了TypeScript(Update 2将为您提供最新版本的2.3,并允许并行安装).如果您没有它,则可以通过Visual Studio安装程序添加它-在安装程序中,单击汉堡"菜单并选择修改",然后单击单个组件",然后在SDK,库和框架下可以添加TypeScript.

So TypeScript is installed by default with VS2017 (Update 2 will give you the latest version of 2.3 and allow side by side installs). If you don't have it you can add it via the Visual Studio Installer - from the installer click the burger menu and choose Modify, then click Individual Components and under SDKs, Libraries and Frameworks you can add TypeScript.

安装后,您可以添加tsconfig.json文件来告诉TypeScript编译器如何工作,例如:

Once installed you can add a tsconfig.json file to tell the TypeScript compiler how to behave, example here:

{
    "compileOnSave": true,
    "compilerOptions":
    {
        "noImplicitAny": false,
        "noEmitOnError": true,
        "removeComments": false,
        "sourceMap": true,
        "target": "es5"
    },
    "exclude":
    [
        "node_modules"
    ]
}

重要的设置是compileOnSave,它告诉VS在保存ts时编译js文件.

The important setting is compileOnSave which tells VS to compile the js file when you save the ts.

现在您应该看到TypeScript文件中有一个嵌套的Javascript文件:

You should now see you have a nested Javascript file within your TypeScript file:

现在,您只需要并排打开两个文件,当您保存ts时,js将自动更新(如果VS提示您将更改后的文件加载到磁盘上,这有助于勾选始终更新"选项).

Now you just need to open both files side by side and when you save the ts then js will automatically update (it helps to tick the always update option if VS prompts you to load the changed file on disk).

这篇关于对Visual Studio 2017的打字稿支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆