VSCode TypeScript Intellisense not working

后端 未结 1 1637
迷失自我
迷失自我 2021-01-15 21:05

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.

I\'ve tried targeting es5, es6, with or without commonj

相关标签:
1条回答
  • 2021-01-15 21:13

    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.

    Create a new Typescript project from the command prompt:

    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

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

    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.

    Instead of this:

    var http = require("http");
    

    Type this:

    import http = require("http");
    

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

    0 讨论(0)
提交回复
热议问题