Should I install @types/node? It seems like VSCode automatically has it installed

Viewed 975

I saw a lot of people installing @types/node in their dev dependencies.

However, if you open an empty folder in VSCode, and create an empty js file, and then you type:

const fs = require('fs'); // <= hover it and type shows!

Why is this happening? Does VSCode automatically have it installed?

1 Answers

If you are working with TypeScript, you must manually manage these types packages. This is required because types are part of the TypeScript compile process, so they are treated like real dependencies

For JavaScript however, in most cases the types are only used to offer improved IntelliSense. VS Code often can infer which types packages to download by looking at the import statements and require calls in code and will then download these types using automatic type acquisition. With automatic type acquisition, you do not need to install anything and your local node_modules is never modified.

If automatic type acquisition does not kick in for some reason, you can always install the types manually.

See the VS Code JS IntelliSense documentation for more details

Related