简体   繁体   English

要使VSCode与TypeScript一起使用,需要什么配置?

[英]What configuration is required to get VSCode working with TypeScript?

I am trying to get VSCode up and running with TypeScript and am having little success. 我正在尝试使VSCode启动并与TypeScript一起运行,但收效甚微。

I am looking at the following: 我在看以下内容:

https://code.visualstudio.com/docs/languages/typescript https://code.visualstudio.com/docs/languages/typescript

It looks like once you have installed the compiler VSCode should just work but given the following: 看起来,一旦您安装了编译器VSCode,它就可以正常工作,但是具有以下条件:

tsconfig.json tsconfig.json

{
  { 
  "compilerOptions": {
    "target": "es5",                          
    "module": "commonjs",                     
    "esModuleInterop": true                  
  }
}

package.json package.json

{
  "name": "blahh",
  "version": "1.0.0",
  "description": "tryme",
  "main": "index.js",
  "author": "ghost",
  "license": "MIT",
  "devDependencies": {
    "typescript": "^3.4.5"
  }
}

tasks.json task.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "tsc-watch",
      "command": "tsc",
      "args": ["-w", "-p", "."],
      "type":"shell",
      "isBackground": true,
      "group":"build",
      "problemMatcher": "$tslint5",
      "presentation":{
        "reveal": "always",
      }
    }
  ]
}

Project 项目

在此处输入图片说明

HelloWorld.ts HelloWorld.ts

function sayHello(name: string): void {
    console.log(`Hello ${name}!`);
}

sayHello(1);

Running the build task or tsc from the terminal correctly indicates an error until I change the 1 to a string then generates HelloWorld.js. 从终端正确运行构建任务或tsc会指示错误,直到我将1更改为字符串然后生成HelloWorld.js。 The editor, however, is not working in that there is no intelliSense, code completion or error highlighting. 但是,该编辑器无法正常运行,因为没有intelliSense,代码完成或错误突出显示。

I have tried the following but this also has not worked: 我已经尝试了以下方法,但是也没有用:

VSCode TypeScript Intellisense not working VSCode TypeScript Intellisense无法正常工作

Other observations: 其他观察:

  1. No TypeScript version number shown in the border of the editor (as I see on the example screenshots I see) 在编辑器的边框中没有显示TypeScript版本号(如我在示例屏幕截图中所看到的)

在此处输入图片说明

  1. When adding the build task following: https://code.visualstudio.com/docs/editor/tasks#vscode there were no tsc:* templates shown. 在添加以下构建任务时: https ://code.visualstudio.com/docs/editor/tasks#vscode没有显示tsc:*模板。

VSCode Info VSCode信息

Version: 1.33.1 (user setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17134

Installed Extensions 已安装的扩展

Built In 内建

TypeScript Language Basics: Enabled
... many others 

External 外部

code --install-extension alanz.vscode-hie-server
code --install-extension alefragnani.Bookmarks
code --install-extension andyyaldoo.vscode-json
code --install-extension christian-kohler.path-intellisense
code --install-extension daiyy.quick-html-previewer
code --install-extension eamodio.gitlens
code --install-extension Edka.haskutil
code --install-extension esbenp.prettier-vscode
code --install-extension fabiospampinato.vscode-todo-plus
code --install-extension flowtype.flow-for-vscode
code --install-extension gcazaciuc.vscode-flow-ide
code --install-extension hoovercj.haskell-linter
code --install-extension jcanero.hoogle-vscode
code --install-extension justusadam.language-haskell
code --install-extension karigari.chat
code --install-extension mrmlnc.vscode-duplicate
code --install-extension ms-vscode.vscode-typescript-tslint-plugin
code --install-extension ms-vsliveshare.vsliveshare
code --install-extension ms-vsliveshare.vsliveshare-audio
code --install-extension ms-vsliveshare.vsliveshare-pack
code --install-extension phoityne.phoityne-vscode
code --install-extension SirTobi.code-clip-ring
code --install-extension WakaTime.vscode-wakatime

So what I am I missing / should I check for in my setup to enable the interactive VSCode features for TypeScript? 那么,我想念的是什么/应该在我的设置中检查以为TypeScript启用交互式VSCode功能吗?

Check that the builtin TypeScript and JavaScript Language Features extension is enabled. 检查是否启用了内置的TypeScript and JavaScript Language Features扩展。 To do this, search @builtin typescript the extensions view. 为此,请在扩展视图中搜索@builtin typescript

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM