如何解决JS/Docker - 类型 'Session & Partial<SessionData>'
我正在尝试将 express-session
添加到在 Docker 下运行的 Node.js 应用程序。
阅读大量帖子:
Express Session: Property 'signin' does not exist on type 'Session & Partial<SessionData>'. (2339) https://github.com/DefinitelyTyped/DefinitelyTyped/issues/49941 https://github.com/DefinitelyTyped/DefinitelyTyped/issues/46861
我尝试对 Session
属性进行声明合并,我的 tsconfig.json
如下所示:
"typeRoots": [
"./src/types","./node_modules/@types"
]
在我的 src/types
文件夹中,我有 index.d.ts
文件:
declare module 'express-session' {
interface Session {
user: string;
}
}
但是当我使用 docker-compose up
命令运行我的项目时,它给了我以下错误:
/app/node_modules/ts-node/src/index.ts:421
return new TSError(diagnosticText,diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
src/routes/auth.ts(26,17): error TS2339: Property 'user' does not exist on type 'Session & Partial<SessionData>'.
at createTSError (/app/node_modules/ts-node/src/index.ts:421:12
我不认为这是 Docker 问题,因为它发生在 Node.js 应用程序启动期间。 有没有人知道如何解决这个问题?
解决方法
除了上一个答案之外,您必须扩展 SessionData
接口,您可以将 --files
标志用于 ts-node
。
在这个答案post中描述。现在看来 ts-node
不接受您的 tsconfig.json
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。