When I create a new Node project using Typescript, VsCode auto import suggestions do not work at all.
Steps to reproduce:
Create a workspace directory.
Run npm init
specifying main.ts
as entrypoint file.
Import typescript cli npm i typescript
Create tsconfig.json .\node_modules\.bin\tsc --init
Create main.ts containing console.log('Running');
Transpile using .\node_modules\.bin\tsc -w
Run by clicking Debug
in VsCode and using the default Nodejs launch config.
Import a library e.g. Rxjs Import typescript cli npm i rxjs
Result:
In main.ts attempting to use any Rxjs type Observable
, BehaviourSubject
, global operators from
of
sequenceEqual
etc results in no import assistance whatsoever.
I've read the VsCode Typescript docs, there is no hint there of what is wrong. https://code.visualstudio.com/docs/languages/typescript
I've tried explicitly setting include
and exclude
directories in tsconfig.json which also has no effect.
Do I need to manually set some module resolution options in tsconfig or something.
I have no idea, I'm at a loss as to why this doesn't work.
UPDATE:
I managed to get VsCode auto import working by specifying
"typeRoots": [ "node_modules" ]
...in tsconfig.json
The results in a minor issue which is that tsc now reports the error
error TS2688: Cannot find type definition file for '.bin'.
It appears the tsc now tries to read the contents of node_modules.bin which is not helpful. I've tried setting
"exclude": [ "./node_modules/.bin"]
in tsconfig, but that has no effect.