biggora / express-useragent

NodeJS user-agent middleware
http://www.gordejev.lv
MIT License
645 stars 113 forks source link

Property 'useragent' does not exist on type 'Request<ParamsDictionary>' #128

Open haveamission opened 4 years ago

haveamission commented 4 years ago

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);
});
mostafiz93 commented 4 years ago

Facing the same issue.

narendra-manchala commented 4 years ago

Try installing types npm i -D @types/express-useragent

LukeXF commented 3 years ago

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;
}
LukeXF commented 3 years ago

Creating a separate file and importing it higher up solved this issue:

declare global {
    namespace Express {
        interface Request {
            useragent?: any
        }
    }
}