VSCode IntelliSense doesn't suggest Angular modules until imported manually in the project

后端 未结 2 1777
独厮守ぢ
独厮守ぢ 2021-01-21 07:39

First you have to understand that I\'m switching from IntelliJ to VSCode (Maybe I was too comfortable the way IntelliJ was looking for modules).

I\'ll mostly use VSCode

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 08:07

    The only solution I've found so far is adding the path to Angular packages into typeRoots of tsconfig.json. Here's an example:

    "typeRoots": ["node_modules/@types", "node_modules/@angular"]
    

    That way, apart from node_modules/@types, TypeScript looks into the node_modules/@angular folder and its subfolders for type definitions.

    According to the TypeScript docs:

    If typeRoots is specified, only packages under typeRoots will be included.

    I don't actually know why nothing was mentioned on that matter in the Angular documentation, which is correct but sounds a bit incomplete in terms of typing discovery:

    Many libraries include definition files in their npm packages where both the TypeScript compiler and editors can find them. Angular is one such library. The node_modules/@angular/core/ folder of any Angular application contains several d.ts files that describe parts of Angular.

    You don't need to do anything to get typings files for library packages that include d.ts files. Angular packages include them already.

提交回复
热议问题