Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading