1

我正在使用打字稿作为我的网络应用程序的后端,并且我已经合并了 express-session。我有 @types/express 和 @types/express-session 但不幸的是我不断收到类型错误说明:

  • Property 'session' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'

有谁知道发生了什么?

版本:

"express": "^4.17.1",
"express-session": "^1.17.1",
"@types/express": "^4.17.11",
"@types/express-session": "1.17.0",

示例代码:

const auth_data: authSuccess|authError = await discordClient.exchangeCodeForTokens(String(disCode));
if(!auth_data) {throw new Error('Could not Authorize!')}
req.session.oauth = auth_data;

这里的最后一行会抛出类型错误:Property 'session' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'

4

1 回答 1

0

问题是我像这样导入了快速会话:

  • const session = require('express-session')

而不是这样:

  • import session from 'express-session';

这完全有道理。我不知道为什么我不考虑看我的进口商品!

于 2021-01-21T04:34:25.320 回答