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

查看:21
本文介绍了对 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?

推荐答案

所以 TypeScript 默认安装在 VS2017 中(更新 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天全站免登陆