Home > OS >  How to get NodeJS and node-modules type hints in VS Code?
How to get NodeJS and node-modules type hints in VS Code?

Time:08-20

I have installed VS Code and want to create a simple Express app.

My code right now just looks like this:

import express from "express"

const HTTP_PORT = 1*process.env.PORT || 66600;

const app = express()


app.listen()

When I hover process.env I just get any, instead of {[name:string]:string} or some such. Even process itself is an any type. When I hover app, I just get Function, no hints for stuff like listen, get etc.

I installed these extensions:

  • JavaScript and TypeScript Nightly
  • Node.js Modules Intellisense

How do I configure my dev environment to get full type hints for packages and nodejs core libraries?

CodePudding user response:

You can try to install a package containing the type definitions relative to node.js such as @types/node package.

To install it, just type

npm install --save @types/node

or

yarn add @types/node

...following your package system

Note that you could also install other @type packages following what package definitions are missing.

CodePudding user response:

I think you migght need to add express types explicity, do npm i @types/express or yarn add @types/express. With regards to process.env, you cant get type inference because typescript doesnt know anything about your a files that are not in its scan area, its only looking for node modules, ts,and js files when your env variables are in your zshrc file or bashrc file or whatever it is on windows, maybe there is a vs-code plugin for it but im not aware of that

  • Related