I am making use of express and passport in my application, In both packages, there's a user attribute under the Request interface. Currently, express has a user attribute but no other properties attached to it in the request object, e.g req.user. I am trying to do a declaration merge (not really sure if this is the right term for it) for express in order to tell typescript that Express.Request.user has an id attribute attached to it like so:
declare namespace Express {
export interface Request {
user: {
id: string
}
}
}
At the same time also, passport has a user attribute but with the value of Express.User. When I do that declaration merge above, I get an error that says All declarations of 'user' must have identical modifiers. Here's the declaration file for passport.
interface User {}
interface Request {
authInfo?: AuthInfo;
user?: User;
// These declarations are merged into express's Request type
login(user: User, done: (err: any) => void): void;
login(user: User, options: any, done: (err: any) => void): void;
logIn(user: User, done: (err: any) => void): void;
logIn(user: User, options: any, done: (err: any) => void): void;
logout(): void;
logOut(): void;
isAuthenticated(): this is AuthenticatedRequest;
isUnauthenticated(): this is UnauthenticatedRequest;
}
I understand it's because of a mismatch in the interfaces, but how do I overcome this? Any help is welcome. Thank you very much!