Mrtenz / typeorm-store

A TypeORM-based store for express-session.
MIT License
16 stars 12 forks source link

Type error when setting up connection #3

Open reggi opened 5 years ago

reggi commented 5 years ago
Type 'Repository<Session>' is not assignable to type 'Repository<SessionEntity>'.
  Types of property 'findOne' are incompatible.
    Type '{ (id?: string | number | Date | ObjectID, options?: FindOneOptions<Session>): Promise<Session>; (options?: FindOneOptions<Session>): Promise<Session>; (conditions?: FindConditions<Session>, options?: FindOneOptions<...>): Promise<...>; }' is not assignable to type '{ (id?: string | number | Date | ObjectID, options?: FindOneOptions<SessionEntity>): Promise<SessionEntity>; (options?: FindOneOptions<SessionEntity>): Promise<SessionEntity>; (conditions?: FindConditions<...>, options?: FindOneOptions<...>): Promise<...>; }'.
giangldo commented 5 years ago

Hi Reggi,

Try this: export class Session implements SessionEntity

swordensen commented 5 years ago

Since this is still open I just wanted to mention that this is a typescript conflict that can be temporarily resolved with some type assertion.

Example:

    const repository: Repository<SessionEntity> = (connection.getRepository(
      Session
    ) as unknown) as Repository<SessionEntity>;

Then you can initialize your session like normal

Example:

app.use(
      session({
        secret: 'yoursuperdupersecret',
        resave: false,
        saveUninitialized: false,
        store: new TypeormStore({ repository }),
        cookie: {
          maxAge: 3600000,
        }
      })