不要怂,就是干,撸起袖子干!

Commit fecc67fe by Abdul Raheem Committed by GitHub

Issue 13302 (#13477)

* fix(types): add overload type for findAndCountAll with group

add overload type for findAndCountAll:
 - add overload type for findAndCountAll with group.
 - add test for checking return type of findAndCountAll with and without group

Closes #13302

* docs: update return type of findAndCountAll in model.js comment

Closes #13302

* fix(types): update overload findAndCountAll position

Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
1 parent 26b62c7c
...@@ -2069,7 +2069,7 @@ class Model { ...@@ -2069,7 +2069,7 @@ class Model {
* @see * @see
* {@link Model.count} for a specification of count options * {@link Model.count} for a specification of count options
* *
* @returns {Promise<{count: number, rows: Model[]}>} * @returns {Promise<{count: number | number[], rows: Model[]}>}
*/ */
static async findAndCountAll(options) { static async findAndCountAll(options) {
if (options !== undefined && !_.isPlainObject(options)) { if (options !== undefined && !_.isPlainObject(options)) {
......
...@@ -1921,6 +1921,10 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut ...@@ -1921,6 +1921,10 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
*/ */
public static findAndCountAll<M extends Model>( public static findAndCountAll<M extends Model>(
this: ModelStatic<M>, this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']> & { group: GroupOption }
): Promise<{ rows: M[]; count: number[] }>;
public static findAndCountAll<M extends Model>(
this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']> options?: FindAndCountOptions<M['_attributes']>
): Promise<{ rows: M[]; count: number }>; ): Promise<{ rows: M[]; count: number }>;
......
...@@ -42,6 +42,16 @@ MyModel.findOne({ include: ['OtherModelAlias'] }); ...@@ -42,6 +42,16 @@ MyModel.findOne({ include: ['OtherModelAlias'] });
MyModel.findOne({ include: OtherModel }); MyModel.findOne({ include: OtherModel });
MyModel.findAndCountAll({ include: OtherModel }).then(({ count, rows }) => {
expectTypeOf(count).toEqualTypeOf<number>();
expectTypeOf(rows).toEqualTypeOf<MyModel[]>();
});
MyModel.findAndCountAll({ include: OtherModel, group: ['MyModel.num'] }).then(({ count, rows }) => {
expectTypeOf(count).toEqualTypeOf<number[]>();
expectTypeOf(rows).toEqualTypeOf<MyModel[]>();
});
MyModel.count({ include: OtherModel }); MyModel.count({ include: OtherModel });
MyModel.count({ include: [MyModel], where: { '$num$': [10, 120] } }); MyModel.count({ include: [MyModel], where: { '$num$': [10, 120] } });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!