[英]Express.js/Typescript: Error TS2339: Property 'send' does not exist on type 'Response'
I'm seeing this in Phpstorm 2019.3 with a red lint under.send()我在 Phpstorm 2019.3 中看到了这个,在 under.send() 下有红色棉绒
// package.json
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@types/express": "^4.17.2",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
// index.ts
const express = require("express")();
express.get('/', (req: Request, res: Response): void => {
res.send('Express App Running') // TS2339: Property 'send' does not exist on type 'Response'
});
Are these the wrong type definitions or is something else at play?这些是错误的类型定义还是其他原因?
The Request
and Response
types in the callback are probably not the ones provided by Express.回调中的Request
和Response
类型可能不是 Express 提供的类型。
Make sure you import the right types:确保导入正确的类型:
import express, { Request, Response } from "express";
const app = express();
app.get("/", (req: Request, res: Response) => {
res.send("foo");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.