Sequelize-typescript: order inside findOrCreate

Created on 25 Jul 2019  路  3Comments  路  Source: RobinBuschmann/sequelize-typescript

https://github.com/sequelize/sequelize/issues/11081#issuecomment-515114663

This does not work:

    Purchase.scope(scope).findOrCreate({
      where: {
        referenceId: 5,
      },
      order: [["updatedAt", "DESC"]],
    });

The typescript error:

Argument of type '{ where: { referenceId: number; }; order: string[][]; }' is not assignable to parameter of type 'FindOrCreateOptions'.
  Object literal may only specify known properties, and 'order' does not exist in type 'FindOrCreateOptions'.ts(2345)

Environment

sequelize-typescript: 1.0.0-beta.3
Dialect:

  • [ ] mysql
  • [ X ] postgres
  • [ ] sqlite
  • [ ] mssql
  • [ ] any
    Dialect library version: pg version 6.4.2
    Database version: 9.6.12
    Sequelize version: 5.8.10 (or 5.10.3 same issue)
    Node Version: 8.11.4 (or 10.16.0 same issue)
    OS: macOS 10.14.5
    TypeScript version: 3.4.3 (or 3.3.3 same issue)

Most helpful comment

This is a sequelize issue. Since 1.0.0 sequelize-typescript uses the official typings of sequelize. According to their typings, order: [["updatedAt", "DESC"]], is not allowed here. As you can see here: https://github.com/sequelize/sequelize/blob/master/types/lib/model.d.ts#L667 FindOrCreateOptions has no order property, since FindOrCreateOptions doesn't extend IncludeOptions

All 3 comments

Is this a sequelize or sequelize-typescript issue ?
https://github.com/sequelize/sequelize/issues/11081#issuecomment-515114663

This is a sequelize issue. Since 1.0.0 sequelize-typescript uses the official typings of sequelize. According to their typings, order: [["updatedAt", "DESC"]], is not allowed here. As you can see here: https://github.com/sequelize/sequelize/blob/master/types/lib/model.d.ts#L667 FindOrCreateOptions has no order property, since FindOrCreateOptions doesn't extend IncludeOptions

Closing this, since it is a sequelize issue - not a sequelize-typescript one

Was this page helpful?
0 / 5 - 0 ratings