Open OmkarK45 opened 2 years ago
Hello @OmkarK45, just curious, did you find a solution / workaround for this issue?
Hello @OmkarK45, just curious, did you find a solution / workaround for this issue?
Unfortunately, no..
Hi! You shouldn't force req
to be of type ExpressRequest
in your request handlers.
You can use global declaration merging instead. So that the Request
type is changed globally to have your user?: User
type.
Add a global.d.ts
at the root of your project and inside, put the following:
import { User } from './path/to/User';
declare global {
namespace Express {
interface Request {
user?: User,
}
}
}
With this, when you will import { Request } from 'express'
, you'll have the user
property directly in it. So you'll be able to use async (req, res) => { }
like before, without specifying the type of req
, and it should remain "custom typed".
Hi there! Thank you for creating this middleware. I'm using express-session and have attached
user
object to express request.However, when I type my request to Express request, I lose all the typesafety provided by this plugin.
any help would be appreciated 😄