The req variable of Request type has no intellisense for property body. Is this due to the typings?
import { Request, Response } from 'express'
import { ok, bad } from './responses'
export const signIn: async (req: Request, res: Response) => {
try {
const { name, pword } = req.body // body is not recognized
const data = auth.signIn(name, password)
ok(res, data)
} catch (error) {
bad(res, error)
}
}
body-parser had been removed from express 4 into separate project, so there won't be any type definition about it.
I use it this way:
import * as bodyParser from 'body-parser';
let router: Router = express.Router();
router.use(bodyParser.text());
(req: Request, res: Response) => {
let address = req['body'];
}
instead of
typings install express --save-dev
i did
npm install @typings/express --save-dev
and it gave me 'req.body'
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