sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Type Error using sub querys, sum, count, etc.

Open andre-muller opened this issue 4 years ago • 3 comments

Versions

  • sequelize: ^6.5.0
  • sequelize-typescript: ^2.0.0
  • typescript ^3.6.3

I'm submitting a ...

[ X ] bug report [ ] feature request

Actual behavior:

When I do some subquery or sum, count, etc. The typescript informs an error because the return is not in Model.

Screen Shot 2021-02-11 at 12 28 35 PM

-->

const [{ totalDuration }] = await TaskModel.findAll({
      attributes: [
        [Sequelize.fn('sum', Sequelize.col('duration')), 'totalDuration'],
      ],
      group: ['task_list_id'],
      where: {
        task_list_id: id,
        status: { [Op.or]: ['in_progress', 'not_started'] },
      },
    });

andre-muller avatar Feb 11 '21 19:02 andre-muller

Having the same issue.

mhuggins avatar Jun 18 '22 02:06 mhuggins

Workaround is to add declare totalDuration: number | undefined to your Model, but it's not an ideal solution.

ozgb avatar Feb 13 '23 15:02 ozgb

Getting same error

chandrashekhar07 avatar May 07 '23 07:05 chandrashekhar07