简体   繁体   中英

Node types not working in typescript

I have included a Typescript definition file so that I can program my very basic node express server in Typescript. I have installed the types using:

npm install @types/node --save-dev

Sadly, my IDE (VS Code) still doesn't recognise the Node typings:

server.ts

import * as express from "express";

const app = express();

app.get('/', (req, res) => {
  res.send('Hello Typescript!')
});

const server = app.listen(3000, () => {
  console.log("listening on port 3000")
})

errors

app.get Property 'get' does not exist on type 'Function'

app.listen Property 'listen' does not exist on type 'Function'

You will also need types for Express:

npm install @types/express --save-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM