Node.js 如何使用TypeScript在express中键入app.get(';/events';,(req,res)
我想知道在express中使用Node.js 如何使用TypeScript在express中键入app.get(';/events';,(req,res),node.js,typescript,express,Node.js,Typescript,Express,我想知道在express中使用app.get时(req,res)=>的类型注释是什么 app.get('/events', (req, res) => { // SSE Setup res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'ke
app.get
时(req,res)=>
的类型注释是什么
app.get('/events', (req, res) => {
// SSE Setup
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
});
res.write('\n');
sseEvents(req, res);
});
您需要有
@types/express
(npmi-D@types/express
),然后才能使用
import { Request, Response } from 'express';
app.get('/events', (req: Request, res: Response) => {
// your code
});