Now im following the Fullstack React GraphQL TypeScript Tutorial
I get trouble in connectRedis with express-session;;;
import connectRedis from "connect-redis";
import session from "express-session";
...
const RedisStore = connectRedis(session);
[ERROR]
error TS2345: Argument of type 'typeof session' is not assignable to parameter of type '(options?: SessionOptions | undefined) => RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
Types of parameters 'options' and 'options' are incompatible.
Type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/connect-redis/node_modules/@types/express-session/index").SessionOptions | undefined' is not assignable to type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/express-session/index").SessionOptions | undefined'.
Type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/connect-redis/node_modules/@types/express-session/index").SessionOptions' is not assignable to type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/express-session/index").SessionOptions'.
Types of property 'store' are incompatible.
Type 'Store | undefined' is not assignable to type 'Store | MemoryStore | undefined'.
Type 'Store' is not assignable to type 'Store | MemoryStore | undefined'.
Type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/connect-redis/node_modules/@types/express-session/index").Store' is not assignable to type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/express-session/index").Store'.
Types of property 'load' are incompatible.
Type '(sid: string, callback: (err: any, session?: SessionData | undefined) => any) => void' is not assignable to type '(sid: string, fn: (err: any, session?: SessionData | null | undefined) => any) => void'.
Types of parameters 'callback' and 'fn' are incompatible.
Types of parameters 'session' and 'session' are incompatible.
Type 'SessionData | undefined' is not assignable to type 'SessionData | null | undefined'.
Type 'import("/Users/jsyovo/Documents/2-MyRepository/2-ReactJS/14-reddit-clone/server/node_modules/@types/connect-redis/node_modules/@types/express-session/index").SessionData' is not assignable to type 'Express.SessionData'.
The types of 'cookie.path' are incompatible between these types.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
22 const RedisStore = connectRedis(session);
2
Answers
Try rolling back to
I have similar problems, and rolling back helps, although I do not think it is a good practice. I believe something wrong about typing in the new versions of these package
Well, I tried using the newest packages again, and remove "dist" and "tsc -w" again. There is no such error. So not sure what exactly the mechanism is.
I had a similar problem but surprisingly enough (and honestly, not entirely sure why this is so but anyway..) keeping the "require" instead of converting to "import" solved this problem for me.
When I had redis setup exactly as the documentation from connect-redis, it seems to work fine but somehow converting to import created problems.
If anyone can explain why this is happening, would be much appreciated!
FYI here are my package versions (all latest versions up to date):
I ran into this problem while following Ben Awad’s Fullstack React GraphQL Typescript Tutorial on youtube and when i undid the import conversion, code seemed to work well lol