1

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?

1
  • Note that I did develop express and other apps in Visual Studio 2019 and there everything worked, so there must be a way. I just need to know how to configure the packages. Commented Aug 19, 2022 at 11:02

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Ok thanks. I understand that the IDE does not understand I am writing a script for node.js. But is there a way to tell it? I guess Node does not have that many internals for me to care, but it would be nice if I could fix it.
ohhh for that u need to add an install for node types so npm i @types/node or yarn add @types/node, is that the answer or maybe i dont understand the question
Yeah, that was the question, thanks a lot. Btw did you ever had any trouble installing these? For anything from the @types project I just get errors... It's definitelly my system issue, but was wondering if you know where to get help on this...
not all modules have or even need @types, some packages/modules declare their own types so you dont need to add any extra installation, some packages are even just strictly js, so you cant get any type interference at all. it just so happens the ones u packages u wanted, dont include their types, to see packages that u can install with @types/{package_name} use this link
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.