查看VS代码设置,似乎没有一个选项,在每个项目的基础上,设置Typescript编译器.我可以设置VS Code使用我通过NPM安装的1.5 alpha编译器吗?在tsconfig文件中引用此编译器是否有效?
编辑:只想添加我想编译到ES6,如果这有所作为.
我在Visual Studio Code中已经将ES6定位了一段时间,但是当我尝试切换到TypeScript时,它会抛出错误,例如:
生成器仅在定位ECMAScript 6时可用
但我的tsconfig.json确实有ES6目标:
{
"compilerOptions": {
"target": "ES6",
"module": "amd",
"sourceMap": true
}
}
Run Code Online (Sandbox Code Playgroud)
所以我试过npm install -g typescript@1.6.0-beta但看起来VSCode并不关心.
目前不支持生成器.
如何在VS Code中使TypeScript和生成器一起正常工作?
更改typescript.tsdk为1.6二进制文件似乎修复了IntelliSense错误,但是这个tasks.json仍打印出来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"
Run Code Online (Sandbox Code Playgroud)
但是,/usr/local/lib/node_modules/typescript/bin/tsc --target ES6 app.ts在终端中手动使用确实有效.
我正在尝试使用 TypeScript 启动并运行 VSCode,但收效甚微。
我正在查看以下内容:
https://code.visualstudio.com/docs/languages/typescript
看起来一旦你安装了编译器 VSCode 应该就可以工作了,但给出了以下内容:
配置文件
{
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"esModuleInterop": true
}
}
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "blahh",
"version": "1.0.0",
"description": "tryme",
"main": "index.js",
"author": "ghost",
"license": "MIT",
"devDependencies": {
"typescript": "^3.4.5"
}
}
Run Code Online (Sandbox Code Playgroud)
任务文件
{
"version": "2.0.0",
"tasks": [
{
"label": "tsc-watch",
"command": "tsc",
"args": ["-w", "-p", "."],
"type":"shell",
"isBackground": true,
"group":"build",
"problemMatcher": "$tslint5",
"presentation":{
"reveal": "always",
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
项目
HelloWorld.ts
function sayHello(name: string): void {
console.log(`Hello ${name}!`);
} …Run Code Online (Sandbox Code Playgroud)