I'm seeing this in Phpstorm 2019.3 with a red lint 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 "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names. Copied!
The "Property does not exist on type Request" error occurs when we access a property that does not exist in the Request interface. To solve the error, extend the Request interface in a . d. ts file adding the property you intend to access on the request object.
The Request
and Response
types in the callback are probably not the ones provided by 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");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With