Visual Studio Code Automatic Imports

前端 未结 12 1218
轻奢々
轻奢々 2020-12-02 11:00

I\'m in the process of making the move from Webstorm to Visual Studio Code. The Performance in Webstorm is abysmal.

Visual studio code isn\'t being very helpful abo

相关标签:
12条回答
  • 2020-12-02 11:26

    There is a Visual Studio Code issue you can track and thumbs up for this feature. There was also a User Voice issue, but I believe they moved voting to GitHub issues.

    It seems they want auto import functionality in TypeScript, so it can be reused. TypeScript auto import issue to track and thumbs up here.

    0 讨论(0)
  • 2020-12-02 11:27

    2018 now. You don't need any extensions for auto-imports in Javascript (as long as you have checkjs: true in your jsconfig.json file) and TypeScript.

    There are two types of auto imports: the add missing import quick fix which shows up as a lightbulb on errors:

    And the auto import suggestions. These show up a suggestion items as you type. Accepting an auto import suggestion automatically adds the import at the top of the file

    Both should work out of the box with JavaScript and TypeScript. If auto imports still do not work for you, please open an issue

    0 讨论(0)
  • 2020-12-02 11:28

    If you are using angular, check that the tsconfig.json does not contain errors. (in the problems terminal)

    For some reason I doubled these lines, and it didn't work for me

    {
      "module": "esnext",
      "moduleResolution": "node",
    }
    
    0 讨论(0)
  • 2020-12-02 11:32

    I am using 'ImportJS' plugin by Devin Abbott for auto import and you can install this using below code

    npm install --global import-js

    0 讨论(0)
  • 2020-12-02 11:33

    I used Auto Import plugin by steoates which is quite easy.

    Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX.

    0 讨论(0)
  • 2020-12-02 11:36

    In the tsconfig.app.json, a standard Angular 10 app has:

    {
      "extends": "./tsconfig.base.json",
      "compilerOptions": {
        "outDir": "./out-tsc/app",
        "types": []
      },
      "files": [
        "src/main.ts",
        "src/polyfills.ts"
      ],
      "include": [
        "src/**/*.d.ts"
      ]
    }
    

    Once I changed the include like to be:

      "include": [
        "src/**/*.d.ts",
        "src/**/*.ts"
      ]
    

    It worked for me

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