-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Rework association methods for better TS support #14302
Comments
Update: After a quick test this would enable having smart typings for the |
This RFC would also allow us to resolve #7621, as pluralization is used in associations method names |
Note from https://gist.github.com/ephys/078ee6a2eb31dc209f0de6cea95316e7: This would also simplify adding QueryBuilder support: // non qb version
user.projects.findAll()
// qb version
user.projects.select()
.orderBy('id', 'ASC')
.findAll() |
This would be amazing! Would be a game-changer to reducing developer mistakes. |
Caveat: It's not possible to infer the types of static class fields based on generics.
I think we could deprecate and replace |
Is this planned to be held off until v8/beyond or would work on this be accepted? |
Is your feature request related to a problem? Please describe.
The way association methods are generated today is cumbersome when using TypeScript.
sequelize-typescript
solves this by adding$get
,$count
, etc methods.Describe the solution you'd like
I think we could improve developer ergonomics by grouping generated methods in one object.
So instead of looking like this
The association would look like this:
with
HasManyAttribute
looking like thisThis would also open the door for a clean decorator support
Why should this be in Sequelize
I think this way is less verbode, less error prone, and improves typescript users ergonomics.
This solution also enables us to add smart typings for the
associations
static property. Demo hereNote that this would be a pretty big breaking change.
Describe alternatives/workarounds you've considered
The way sequelize-typescript does it. But this solution lets us use different typings for each association type.
Feature Request Checklist
Is this feature dialect-specific?
Would you be willing to implement this feature by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: