prisma-session-store: Incompatible instance typing while assigning to express-session's store

Got an incompatible instance typing while assigning to express-session’s store with the 3.1.10 release as follows:

src/main.ts:48:7 - error TS2740: Type 'PrismaSessionStore<"session">' is missing the following properties from type 'Store': regenerate, load, createSession, addListener, and 14 more.

48       store: new PrismaSessionStore(prismaService, {
         ~~~~~

  node_modules/@types/express-session/index.d.ts:94:9
    94         store?: Store | undefined;
               ~~~~~
    The expected type comes from property 'store' which is declared here on type 'SessionOptions'

src/main.ts:

app.use(
  expressSession({
    secret: 'very-confidential-secret',
    resave: false,
    saveUninitialized: false,
    store: new PrismaSessionStore(prismaService, {
      checkPeriod: 2 * 60 * 1000, //ms
      dbRecordIdIsSessionId: true,
      dbRecordIdFunction: undefined,
    }),
  })
);

package.json:

{
  "dependencies": {
    "@quixo3/prisma-session-store": "^3.1.9",
    "express-session": "^1.17.3",
  }
}

These configurations work just fine before with the 3.1.9 release. Is there anything needs to be done or are there any migration steps should be followed in order to make it works with the latest release?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 3
  • Comments: 21 (10 by maintainers)

Most upvoted comments

I’m getting a similar error, this is my setup:

app.use(session({
  secret: 'this-should-be-very-random',
  resave: true,
  saveUninitialized: false,
  store: new PrismaSessionStore(
    new PrismaClient(),
    {
      checkPeriod: 2 * 60 * 1000,  //ms
      dbRecordIdIsSessionId: true,
      dbRecordIdFunction: undefined,
    }
  )
}));

and TypeScript is throwing this error:

Argument of type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>' is not assignable to parameter of type 'IPrisma<"session">'.

  Property 'session' is missing in type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>' but required in type 'Record<"session", { create(args: ICreateArgs): Promise<IPrismaSession>; delete(args: IDeleteArgs): Promise<IPrismaSession>; deleteMany(args?: unknown): Promise<...>; findMany(args?: IFindManyArgs | undefined): Promise<...>; findUnique(args: IFindUniqueArgs): Promise<...>; update(args: IUpdateArgs): Promise<...>; }>'.ts(2345)

I only have the issue with the typing error and “session” when the schema is missing the “Session” type or the client has not been generated properly npx prisma generate.

Anyone having this issue I would check the generated “PrismaClient” from the node_modules folder (or wherever you put it) has the the “session” property from the Session model.

all of your models should be a property on the client

const prisma = new PrismaClient();
prisma.session.findOne();
prisma.myOtherType.findAll();

Of course check this is in your schema

model Session {
  id        String   @id
  sid       String   @unique
  data      String
  expiresAt DateTime
}

Using Express v5

    "express": "^5.0.0-beta.1",
    "@types/express": "^4.17.17",
    "express-session": "^1.17.3",
    "@types/express-session": "^1.17.6",

Hi @olalonde, For context, are you using NestJs? What version of Express / Express Session are you seeing this with? Thanks for posting, -K

Hi, I have the same problem with NestJS, any news?