express-useragent
express-useragent copied to clipboard
Property 'useragent' does not exist on type 'Request<ParamsDictionary>'
Trying to use express-useragent with NodeJS/Express/TypeScript and getting this error.
Code:
app.get("/chat", keycloak.protect(), async (req, res) => {
let chatController = new ChatController();
let url = await chatController.openAppChat(req.useragent, channeluserId, merchantName);
res.redirect(url);
});
Facing the same issue.
Try installing types npm i -D @types/express-useragent
Facing same issue I tried creating a global types file as well and this doesn't solve it, neither does @narendra67 answer.
import express from "express"
export default interface IRequest extends express.Request {
useragent?: any;
}
Creating a separate file and importing it higher up solved this issue:
declare global {
namespace Express {
interface Request {
useragent?: any
}
}
}