Skip to content

Commit

Permalink
fix(model): fix count with grouping typing (#13884)
Browse files Browse the repository at this point in the history
* fix(model): fix count with grouping typing

Fixes #13871

* test: update Model.count(group) typing test

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
  • Loading branch information
ephys and sdepold committed Jan 4, 2022
1 parent b315ce8 commit 49beb29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion types/lib/model.d.ts
Expand Up @@ -1907,7 +1907,7 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
public static count<M extends Model>(
this: ModelStatic<M>,
options: CountWithOptions<M['_attributes']>
): Promise<{ [key: string]: number }>;
): Promise<Array<{ [groupKey: string]: unknown, count: number }>>;

/**
* Count the number of records matching the provided where clause.
Expand Down
3 changes: 2 additions & 1 deletion types/test/count.ts
Expand Up @@ -4,7 +4,8 @@ import { Model, Op } from 'sequelize';
class MyModel extends Model {}

expectTypeOf(MyModel.count()).toEqualTypeOf<Promise<number>>();
expectTypeOf(MyModel.count({ group: 'tag' })).toEqualTypeOf<Promise<{ [key: string]: number }>>();
expectTypeOf(MyModel.count({ group: 'tag' }))
.toEqualTypeOf<Promise<Array<{ [groupKey: string]: unknown, count: number }>>>();
expectTypeOf(MyModel.count({ col: 'tag', distinct: true })).toEqualTypeOf<Promise<number>>();
expectTypeOf(MyModel.count({
where: {
Expand Down

0 comments on commit 49beb29

Please sign in to comment.