Skip to content

Commit

Permalink
fix(model.d): fix findAndCountAll.count type (sequelize#13736)
Browse files Browse the repository at this point in the history
* fix(model.d): fix findAndCountAll.count type

`findAndCountAll` should only return `count` as an array when the `group` option is provided.

This means in that case, `options` is no longer optional because when `options` is not provided, it's never a group count.
I also rearrange `findAndCountAll` order to ensure the single count overload is applied first.

* refactor(model): add fix type for findAllAndCount

* refactor(model): tidy up type with SetRequired

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
  • Loading branch information
2 people authored and aliatsis committed Jun 2, 2022
1 parent 38e1a08 commit 9b23fe0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions types/lib/model.d.ts
Expand Up @@ -9,6 +9,7 @@ import { Sequelize, SyncOptions } from './sequelize';
import { LOCK, Transaction } from './transaction';
import { Col, Fn, Literal, Where } from './utils';
import Op = require('./operators');
import { SetRequired } from '../type-helpers/set-required'

export interface Logging {
/**
Expand Down Expand Up @@ -1955,12 +1956,12 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
*/
public static findAndCountAll<M extends Model>(
this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']> & { group: GroupOption }
): Promise<{ rows: M[]; count: number[] }>;
options?: Omit<FindAndCountOptions<M['_attributes']>, 'group'>
): Promise<{ rows: M[]; count: number }>;
public static findAndCountAll<M extends Model>(
this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']>
): Promise<{ rows: M[]; count: number }>;
options: SetRequired<FindAndCountOptions<M['_attributes']>, 'group'>
): Promise<{ rows: M[]; count: number[] }>;

/**
* Find the maximum value of field
Expand Down

0 comments on commit 9b23fe0

Please sign in to comment.