Rez*_*ani 12 node.js express typescript express-session
我正在尝试构建一个 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;
~~~~
Run Code Online (Sandbox Code Playgroud)
对于 connect-mongo lib 类型检查,尝试skipLibCheck
在 tsconfig.json 中添加选项
{
"compilerOptions": {
....
"skipLibCheck": true
}
}
Run Code Online (Sandbox Code Playgroud)
对于内联代码,尝试添加 // @ts-ignore
// @ts-ignore
req.session.user = user;
Run Code Online (Sandbox Code Playgroud)
请注意,这只是一种解决方法,当我尝试在 DockerHub 上重建 docker 镜像而不更改任何代码时,我今天遇到了同样的问题。
归档时间: |
|
查看次数: |
4329 次 |
最近记录: |