简体   繁体   English

Express.js/Typescript:错误 TS2339:属性“发送”在类型“响应”上不存在

[英]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.回调中的RequestResponse类型可能不是 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.

相关问题 Typescript TS2339 属性不存在 - Typescript TS2339 property does not exist 错误TS2339:类型“ {}”上不存在属性“包含” - error TS2339: Property 'includes' does not exist on type '{}' 错误 TS2339:类型 express“应用程序”上不存在属性“使用” - Error TS2339: Property 'use' does not exist on type express "Application" NodeJS + TypeScript 错误 TS2339:“性能”类型上不存在属性“timeOrigin” - NodeJS + TypeScript Error TS2339: Property 'timeOrigin' does not exist on type 'Performance' 打字稿错误:TS2339:类型“字符串”上不存在属性“地图” - Typescript Error: TS2339:Property 'map' does not exist on type 'string' TypeScript 错误 TS2339:类型“用户”上不存在属性“id” - TypeScript error TS2339: Property 'id' does not exist on type ' User' 将打字稿 ^3.7.2 更新为最新的“打字稿”:“^4.4.4” - 错误 TS2339:“导航器”类型上不存在属性“msSaveOrOpenBlob” - After update typescript ^3.7.2 to latest "typescript": "^4.4.4" - error TS2339: Property 'msSaveOrOpenBlob' does not exist on type 'Navigator' TS2339:类型“导航器”上不存在属性“联系人” - TS2339: Property 'contacts' does not exist on type 'Navigator' TS2339:属性“comparePassword”在类型“Model”上不存在<document, {}> '</document,> - TS2339: Property 'comparePassword' does not exist on type 'Model<Document, {}>' 出现“错误 TS2339:“对象”类型上不存在属性“用户”的错误。 ” - Getting error of “error TS2339: Property 'user' does not exist on type 'Object'. ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM