【发布时间】:2021-04-11 11:57:01
【问题描述】:
我正在尝试将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 应用程序启动期间。 有谁知道如何解决这个问题?
【问题讨论】:
标签: javascript node.js typescript docker express-session