类型错误:无法读取未定义的属性(读取“createClient”)
所以我想做的是创建一个会话并将其存储在redis中。 我遵循了此 github 存储库中的 API https://github.com/tj/connect-redis 。
但我在“client”一词中收到此错误:预期类型来自属性“client”,该属性在“RedisStoreOptions”类型上在此处声明。
这是我使用的代码:
import redis from 'redis';
import session from 'express-session';
import connectRedis from 'connect-redis';
const app = express();
const RedisStore = connectRedis(session);
const redisClient = redis.createClient({ legacyMode: true });
redisClient.connect().catch(console.error);
app.use(
session({
store: new RedisStore({ client: redisClient }),
saveUninitialized: false,
secret: "keyboard cat",
resave: false,
})
)
错误发生在这里:
store: new RedisStore({ client: redisClient })
更具体地说,是“客户端”这个词。
so what I want to do is to create a session and store it in redis.
I followed the API from this github repository https://github.com/tj/connect-redis.
But I am getting this error in the word client: The expected type comes from property 'client' which is declared here on type 'RedisStoreOptions'.
This is the code that i used:
import redis from 'redis';
import session from 'express-session';
import connectRedis from 'connect-redis';
const app = express();
const RedisStore = connectRedis(session);
const redisClient = redis.createClient({ legacyMode: true });
redisClient.connect().catch(console.error);
app.use(
session({
store: new RedisStore({ client: redisClient }),
saveUninitialized: false,
secret: "keyboard cat",
resave: false,
})
)
The error occurs here:
store: new RedisStore({ client: redisClient })
More specifically in the word client.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是
使用
instead of
use
我猜你使用的是 TypeScript,我遇到了这个问题,你安装了吗:
我这样做了,但客户端一直出错,所以我卸载了所有 3 个 @types,并注意到 redis 不需要你声明模块,所以我只安装了Express-Session 和 Connect-Redis 的类型
I'm guessing your using TypeScript, I had this issue, did you install:
I did that and kept getting an error with the client so I uninstalled all 3 @types and noticed redis doesn't require you to declare modules so I only installed types for express-session and connect-redis