This is an intentional performance/helpfulness trade-off.
We don't eagerly consume all.d.ts files from node_modules - doing so would be prohibitively expensive in a world where there are regularly possible thousands of definition files in node_modules.
When the Angular .d.ts file isn't consumed, we have no way of knowing that NgModule happens to come from @angular/core, thus can't suggest that auto-import.
Auto complete is one of my favorite features of VS code. But sometimes it doesn't provide what I need.
Steps to Reproduce:
Create a project with create-react-app: npx create-react-app test-auto-complete --typescript
Create a empty file src/test.tsx.
Make sure auto complete works: type isvalid and get following suggestions
Then confirm:
Install a typed package from npm. (I made one - safe-touch
See if auto complete works for the package(type safe and expect suggestion of safeTouch):
Negative :(
There is a difference between the types file of safe-touch and react. Safe-touch's is directly under node_modules while react's is under node_modules/@types/. Then I tried to make a folder under @types for the package, simply cp -r node_modules/safe-touch node_modules/@types.
See if auto complete works now:
It works! 🎉🎉
So it seems that VS code is not able to auto complete types of node_modules/[package] even if the package is correctly typed?
Does this issue occur when all extensions are disabled?: Yes/No
No
The reason for not loading node modules eagerly:
This is an intentional performance/helpfulness trade-off.
We don't eagerly consume all
.d.tsfiles fromnode_modules- doing so would be prohibitively expensive in a world where there are regularly possible thousands of definition files innode_modules.When the Angular
.d.tsfile isn't consumed, we have no way of knowing thatNgModulehappens to come from@angular/core, thus can't suggest that auto-import.Although, you can achieve it using the way mentioned here:
Auto complete is one of my favorite features of VS code. But sometimes it doesn't provide what I need.
Steps to Reproduce:
npx create-react-app test-auto-complete --typescriptsrc/test.tsx.isvalidand get following suggestionssafeand expect suggestion ofsafeTouch):node_moduleswhile react's is undernode_modules/@types/. Then I tried to make a folder under@typesfor the package, simplycp -r node_modules/safe-touch node_modules/@types.So it seems that VS code is not able to auto complete types of
node_modules/[package]even if the package is correctly typed?Does this issue occur when all extensions are disabled?: Yes/No No
Amazing! I didn't knew that! Those are really helpfull links. Thank you @shhdharmen !