首页 > 解决方案 > 命名空间“Express”没有导出成员“SessionData”

问题描述

我正在尝试构建一个 typeScript 项目,但它有一个错误,我不知道它来自哪里,并且自上次以来没有任何变化。


node_modules/connect-mongo/src/types.d.ts:113:66 - error TS2694: Namespace 'Express' has no exported member 'SessionData'.

113         get: (sid: string, callback: (err: any, session: Express.SessionData | null) => void) => void;
                                                                     ~~~~~~~~~~~

node_modules/connect-mongo/src/types.d.ts:114:45 - error TS2694: Namespace 'Express' has no exported member 'SessionData'.

114         set: (sid: string, session: Express.SessionData, callback?: (err: any) => void) => void;
                                                ~~~~~~~~~~~

node_modules/connect-mongo/src/types.d.ts:118:47 - error TS2694: Namespace 'Express' has no exported member 'SessionData'.

118         touch: (sid: string, session: Express.SessionData, callback?: (err: any) => void) => void;
                                                  ~~~~~~~~~~~

src/controllers/http/auth/auth.ts:16:44 - error TS2339: Property 'user' does not exist on type 'Session & Partial<SessionData>'.

16             if (req.session && req.session.user) {
                                              ~~~~

src/controllers/http/auth/auth.ts:41:29 - error TS2339: Property 'user' does not exist on type 'Session & Partial<SessionData>'.

41                 req.session.user = user;
                               ~~~~

打字稿出错的地方

express-session 这是它的导入方式

标签: node.jstypescriptexpressexpress-session

解决方案


我恢复到这个版本来解决这个问题: “@types/express-session”:“1.15.16”,


推荐阅读