diff --git a/package.json b/package.json index 348f90990..aaf25567b 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "@types/csurf": "^1.11.0", "@types/email-templates": "^8.0.1", "@types/express": "^4.17.11", - "@types/express-session": "^1.17.0", + "@types/express-session": "^1.17.3", "@types/lodash": "^4.14.168", "@types/node": "^14.14.22", "@types/node-schedule": "^1.3.1", diff --git a/server/types/express.d.ts b/server/types/express.d.ts index 61f30f0f1..90a880069 100644 --- a/server/types/express.d.ts +++ b/server/types/express.d.ts @@ -4,10 +4,6 @@ import type { User } from '../entity/User'; declare global { namespace Express { - export interface Session { - userId?: number; - } - export interface Request { user?: User; } @@ -19,3 +15,11 @@ declare global { next: NextFunction ) => Promise | void | NextFunction; } + +// Declaration merging to apply our own types to SessionData +// See: (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/express-session/index.d.ts#L23) +declare module 'express-session' { + export interface SessionData { + userId: number; + } +} diff --git a/yarn.lock b/yarn.lock index ec835c003..2b328948c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2070,7 +2070,7 @@ "@types/qs" "*" "@types/range-parser" "*" -"@types/express-session@^1.15.5", "@types/express-session@^1.17.0": +"@types/express-session@^1.15.5": version "1.17.0" resolved "https://registry.yarnpkg.com/@types/express-session/-/express-session-1.17.0.tgz#770daf81368f6278e3e40dd894e1e52abbdca0cd" integrity sha512-OQEHeBFE1UhChVIBhRh9qElHUvTp4BzKKHxMDkGHT7WuYk5eL93hPG7D8YAIkoBSbhNEY0RjreF15zn+U0eLjA== @@ -2078,6 +2078,13 @@ "@types/express" "*" "@types/node" "*" +"@types/express-session@^1.17.3": + version "1.17.3" + resolved "https://registry.yarnpkg.com/@types/express-session/-/express-session-1.17.3.tgz#4a37c5c4428b8f922ac8ac1cb4bd9190a4d2b097" + integrity sha512-57DnyxiqClXOIjoCgeKCUYfKxBPOlOY/k+l1TPK+7bSwyiPTrS5FIk1Ycql7twk4wO7P5lfOVy6akDGiaMSLfw== + dependencies: + "@types/express" "*" + "@types/express@*": version "4.17.8" resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.8.tgz#3df4293293317e61c60137d273a2e96cd8d5f27a"