Incorrect typescript typings for findAndCountAll function #13302
Labels
Comments
|
Ideally, this should be done with function overloading. public static findAndCountAll<M extends Model>(
this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']> & {group: undefined}
): Promise<{ rows: M[]; count: number }>;
public static findAndCountAll<M extends Model>(
this: ModelStatic<M>,
options?: FindAndCountOptions<M['_attributes']> & {group: GroupOption}
): Promise<{ rows: M[]; count: number[] }>;This allows us to dynamically generate a return type based on the developer's input |
|
I would love to take up this issue @Keimeno. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue Description
What are you doing?
I am trying to strongly type my application using Typescript and Sequelize. I have noticed the following behaviour of the
findAndCountAllfunction.Promise<{ rows: M[]; count: number }>.Promise<{ rows: M[]; count: { count: number }[]>>The current type of Sequelize
findAndCountAllisWhat do you expect to happen?
Since
findAndCountAllreturns two different results the type should ideally beI have noticed other attributes also being returned inside the count object so just a
count : { count: number }might not work.What is actually happening?
As discussed in this issue to return the proper count I need to take a count of the returned count array. But since the type says count is a number I am unable to do so.
Following error is thrown
Environment
Issue Template Checklist
How does this problem relate to dialects?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: