如何在Visual Studio代码中使用TypeScript 1.6获取生成器支持? [英] How do I use TypeScript 1.6 with Visual Studio Code to get generators support?

查看:294
本文介绍了如何在Visual Studio代码中使用TypeScript 1.6获取生成器支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Visual Studio代码中定位ES6一段时间,但是当我尝试切换到TypeScript时,会抛出以下错误:

I've been targeting ES6 for a while in Visual Studio Code, but when I try to switch to TypeScript, it throws errors such as:


生成器仅在定位ECMAScript 6时可用

Generators are only available when targeting ECMAScript 6

但是,我的 tsconfig.json ES6目标:

But my tsconfig.json does have the ES6 target:

{
    "compilerOptions": {
        "target": "ES6",
        "module": "amd",
        "sourceMap": true
    }
}

所以我试过 npm install -g typescript@1.6.0-beta ,但看起来VSCode不在乎。

So I tried npm install -g typescript@1.6.0-beta but it looks like VSCode doesn't care.


目前不支持生成器。

Generators are not currently supported.

获取TypeScript和生成器在VS代码中一起正常工作?

How can I get TypeScript and generators to work properly together in VS Code?

更改对于1.6二进制文件,typescript.tsdk 似乎修复了IntelliSense错误,但这个 tasks.json stil l打印出错误TS1220:生成器仅在定位ECMAScript 6或更高版本时可用。

Changing typescript.tsdk to the 1.6 binary seems to fix IntelliSense errors, but this tasks.json still prints out error TS1220: Generators are only available when targeting ECMAScript 6 or higher.:

"version": "0.1.0",
"command": "/usr/local/lib/node_modules/typescript/bin/tsc",
"showOutput": "silent",
"windows": {"command": "tsc.exe"},
"isShellCommand": true,
"args": ["app.ts"],
"problemMatcher": "$tsc"

但是, / usr /在终端中手动使用的local / lib / node_modules / typescript / bin / tsc --target ES6 app.ts 可以正常工作。

推荐答案

我知道了!

您可以使用 typescript.tsdk 设置将VSCode指向TypeScript二进制文件。将您的TypeScript升级到1.6,并正确设置位置。

You can use the typescript.tsdk setting to point VSCode to TypeScript binaries. Upgrade your TypeScript to 1.6 and set the location properly.

您可以在用户/工作区设置或 .vscode / settings中的每个项目中执行.json 文件。 OS X示例:

You can do it either in your user/workspace settings, or per project in the .vscode/settings.json file. OS X example:

"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"



2。编译器



您还需要确保您的 .vscode / tasks.json 指向新的二进制文件,并使编译器在显式项目模式,即使用tsconfig.json而不是将文件列表作为参数进行编译。

2. Compiler

You also need to make sure your .vscode/tasks.json points to the new binary and makes the compiler operate in Explicit project mode, i.e. use tsconfig.json instead of taking a list of files to compile as an argument.

{
    "version": "0.1.0",
    "command": "/usr/local/lib/node_modules/typescript/bin/tsc",
    "showOutput": "silent",
    "windows": {"command": "tsc.exe"},
    "isShellCommand": true,
    "args": [], //do not pass any files to the compiler. This way it will use tsconfig.json where you can set target: "ES6"
    "problemMatcher": "$tsc"
}

最后 tsconfig.json (在项目的根目录中):

And finally tsconfig.json (in the project's root directory):

{
    "compilerOptions": {
        "target": "ES6", //The key, of course.
        "module": "amd",
        "sourceMap": true
    },
    "exclude": [
        "node_modules",
        ".vscode"
    ]
}

随后重新启动编辑器

这篇关于如何在Visual Studio代码中使用TypeScript 1.6获取生成器支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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