sequelize icon indicating copy to clipboard operation
sequelize copied to clipboard

Model.count return type can be an Array

Open bradleyboy opened this issue 7 years ago • 1 comments

Currently, Model.count has this signature:

count(options?: CountOptions): Promise<number>;

However, if you pass group options to the count call, the return is an array. For example, assuming a naive blog posts table with an author_id column:

const count = await Post.count(); 
// returns number

const count = await Post.count({group: ['author_id'], attributes: ['author_id']});
// returns [{count: 1, author_id: 1}, {count: 10, author_id: 2}];

The workaround is to add as any after the call to suppress warnings. Not sure what the proper fix is in the type definition itself, but happy to PR with guidance :)

bradleyboy avatar Sep 04 '17 17:09 bradleyboy

Has anyone found a fix for this yet?

deepaknyk avatar Dec 02 '21 11:12 deepaknyk