when I write this:
import { Request } from 'express-serve-static-core';
router.post((req: Request, res, next) => {
req.session.user = user;
}
tsc gives me an error:
'Object is possibly 'undefined'.
I know the original Request type does not have the session field.
I check @types/express-session index.d.ts file, found this:
declare global {
namespace Express {
interface Request {
session?: Session;
sessionID?: string;
}
//....
}
So I want to add extra field session and sessionID type to the req.
How can I use ? like this: req: Request & ExpressSessionRequest.
So the req will have both original Request type and extra fields type which @types/express-session add.