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
feat(types): simplify Model definitions #14091
Conversation
So this is interesting! The same code that was breaking in #14032 is now breaking here. I'll continue on that other PR to find a solution |
Is this part of one of the RFCs you proposed? |
It was in my personal wishlist but I never opened an actual RFC for this breaking change |
Ah, I read something about |
Since it looks like it's stable (I can't say how many people have used it yet, but it worked in my different projects), I'm going one step further and implementing that missing breaking change :) |
Simpler is always better, hm? :)
What is this User referring to? Another type? Or is the User class? |
```typescript | ||
import { Model, CreationOptional } from 'sequelize'; | ||
|
||
class User extends Model<User> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I have never used this syntax before, I have no clue but I think one would have to call the Model's init function afterwards somehow?
Can you add that to the example?
Itself! It generates its attribute typings from its own class |
Pure magic! I love it! |
I will draft this until #14125 has been resolved We also need a way to define support for includes in class User extends Model<User> {
declare groupId: number;
declare group?: UserGroup;
}
await User2.create({
id: 2,
group: { id: 1 },
}, {
include: [User.associations.group],
}); |
I'll revisit this change when the rest of the project is ready for it |
Pull Request Checklist
yarn test
oryarn test-DIALECT
pass with this change (including linting)?Description Of Change
Pretty large PR, it's a typing breaking change that makes
InferAttributes
the default way of handling attribute typing in v7.So instead of writing:
You now write:
Instead of writing:
You now write:
Extra changes:
Sequelize.define
now usesInferAttributes
too.InferAttributes
& co are purely internal in v7, they are not exported anymore.Model['_attributes']
has been replaced withModel[AttributeSymbol]
to prevent key collision in child models.Attributes<Model>
now supports ModelStatic too! Usefull when used withSequelize.define
The documentation has been updated to reflect this (as a result it's also much, much shorter)
The breaking change has been documented