I get an error with the sendStatus()
function below when I hover on it. The error is:
Property 'sendStatus' does not exist on type 'Response<any, Record<string, any>>'.ts(2339)
My code:
import express from 'express';
import {Request, Response} from "express";
const router = express.Router();
router.post('/blogapi/posts', (req:Request,res : Response) => {
res.sendStatus(200);
});
Please help
CodePudding user response:
You should use res.status, sendStatus does not exist in response.
import express from "express";
import { Request, Response } from "express";
const router = express.Router();
router.post("/blogapi/posts", (req: Request, res: Response) => {
res.status(200).send();
});
CodePudding user response:
This looks like you're not using the proper typing for Express and just have the typing from a plain HTTP response object. .sendStatus()
is an Express-specific method.
As you've discovered, npm install @types/express
will install the appropriate types for Express.