How to get VScode recognize d.ts files without referencing them directly

前端 未结 2 725
一整个雨季
一整个雨季 2021-02-08 04:44

I have a project created with create-react-app-ts

I also have a set of d.ts files that are generated interfaces from JSON-schema. They define some interface

2条回答
  •  野性不改
    2021-02-08 05:13

    If TypeScript compiles without errors, but VSCode still can't recognize global types and add proper intellisense, then it's likely that you have a project with too many files and you are not being specific enough about the files you want TypeScript to check.

    To add intellisense to global types, VSCode iterates over all files available, since you did not specify which ones to check, or was too broad about it. With too many files, VSCode stops looking around.

    Using typeRoots to declare your global types folder/files should be enough for VSCode to spot what files it should look for. If it doesn't happen, consider specifying all the paths you expect intellisense to work in the include field, or remove all the files you don't want in the exclude field. VSCode should follow and add intellisense to the missing files.

    {
      "compilerOptions": {
        "typeRoots": [
          "path/to/**/*.d.ts"
        ],
        "include": [
          // Add all paths you want intellisense to work
          "path/to/where/you/expect/intellisense/to/work",
          "path/to/another/file/or/folder"
        ]
      }
    }
    

提交回复
热议问题