Well I am using express-session, with the typing from definity types (@types/express-session)
I notice that the types don't have anything for custom data in the session fields. Which is not that useful. I wish to extend this to contain (say) userId: number.
The file @types/express-session show it can be done using:
/**
* This interface allows you to declare additional properties on your session object using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
*
* @example
* declare module 'express-session' {
* interface SessionData {
* views: number;
* }
* }
*
*/
So I created a file named ./src/types/types.ts And put the following in it:
declare module 'express-session' {
interface SessionData {
userId: number;
}
}
This "works", in that typescript now sees the correct field. On the other hand everything else exposed by express-sesion is no longer visible, as typescript no longer considers the other module-definition part. Things like import {Session} from "express-session"; now give the error:
TS2305: Module '"express-session"' has no exported member 'Session'.
So how do I extend module definitions?