VSCode TypeScript Intellisense无法正常工作 [英] VSCode TypeScript Intellisense not working

查看:1847
本文介绍了VSCode TypeScript Intellisense无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从字面上看,我正在把头发拉出来.在Mac上为VSCode 1.6.0,打字稿为2.0.2,但我也尝试了2.0.0.

I am pulling my hair out here, literally. VSCode 1.6.0 on Mac, Typescript 2.0.2, but I have also tried 2.0.0.

我已经尝试定位es5,es6,无论是否使用commonjs模块定位.我无法智能感知项目本地的其他文件,也无法获取node_modules文件夹中的任何内容.我什至将来自node_modules的打字稿文件安装到我的打字文件夹中,但这些文件不起作用.

I've tried targeting es5, es6, with or without commonjs module targeting. I can't get intellisense for other files local to my project nor anything in the node_modules folder. I even installed typescript files from node_modules into my typings folder and those don't work.

我获得的唯一智能感知是针对我在全球安装的键入内容.

The only intellisense I get is for my globally installed typings.

{
    "compilerOptions": {
        "target": "es6",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "moduleResolution": "node"
    },
    "exclude": [
        "node_modules"
      ]
}

推荐答案

经过反复试验,终于使Node,Typescript,VSCode(和Visual Studio)以及IntelliSense正常工作.这似乎也可以与WebStorm一起使用.

After lots of trial and error, I finally got Node, Typescript, VSCode (and Visual Studio for that matter), and IntelliSense working correctly. This also appears to work with WebStorm.

在命令提示符下创建一个新的Typescript项目:

Create a new Typescript project from the command prompt:

  1. mkdir newproject(或您想要的任何目录名称)
  2. cd newproject
  3. npm init -f(这将创建一个package.json)
  4. npm install @types/node --save-dev(这将创建一个nodes_module文件夹和一个package-lock.json文件)
  5. 添加初始的tsconfig.json文件.它可能很简单,如{"files" : ["main.ts"] }
  6. 添加一个初始的空main.ts文件以开始使用
  1. mkdir newproject (or any directory name you want)
  2. cd newproject
  3. npm init -f (this will create a package.json)
  4. npm install @types/node --save-dev (this will create a nodes_module folder and a package-lock.json file)
  5. Add an initial tsconfig.json file. It could be as simple as {"files" : ["main.ts"] }
  6. Add an initial empty main.ts file to get started

现在启动VS Code,将其打开以打开在上述步骤中创建的文件夹.

Now launch VS Code point it to open the folder created in the steps above.

最重要.声明模块使用时,请使用import关键字.否则,IntelliSense完全无法使用.我花了好一会儿才意识到这是缺少的一步.

Most important. Use the import keyword when declaring module use. Otherwise, IntelliSense flat out won't work. It took me quite a while a lot of head banging to realize this was the missing step.

代替此:

var http = require("http");

输入以下内容:

import http = require("http");

神奇的是,您已经有了一个使用IntelliSense的准系统Typescript + Node项目.

And magically, you've got a barebones Typescript + Node project with IntelliSense working.

这篇关于VSCode TypeScript Intellisense无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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