sequelize
sequelize copied to clipboard
Model.count return type can be an Array
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 :)
Has anyone found a fix for this yet?