-
Notifications
You must be signed in to change notification settings - Fork 285
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
Fix typeof Model errors throughout by using typeof Model generics #900
Conversation
Codecov Report
@@ Coverage Diff @@
## master #900 +/- ##
=======================================
Coverage 95.20% 95.20%
=======================================
Files 117 117
Lines 1127 1127
Branches 129 129
=======================================
Hits 1073 1073
Misses 22 22
Partials 32 32
Continue to review full report at Codecov.
|
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.
Thanks for your contribution! @KapitanOczywisty
That's great to have a stricter model defintion!
What if I don't want to provide <TCreationAttributes, TModelAttributes>
is it still working ?
It should still works!
Also see my comment. 😄
We should avoid as much as possible any
type, sometime we can't, we need to use any
, we can't do something else.
In my testing both ways work now, seems like @intellix did a great job. When you don't provide attributes you have effectively |
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.
Hey @KapitanOczywisty thanks for fixing this. Can you add some tests please?
@RobinBuschmann I probably could add a couple of types-only tests. What do you want to see in these tests? |
The tests should validate that it's now possible to use |
Sooo, I see problems near everything what is touching And there are also problems with |
@RobinBuschmann Fixed BelongsToMany and some testing added. |
For userland type-guard have to be a bit more finicky and I'm thinking about exporting this one to userland, where you need to access some static properties from Generally, type Properties<T> = {
[P in keyof T]: T[P];
}
type ModelType<TModelAttributes = any, TCreationAttributes = TModelAttributes> = Properties<typeof Model> & (new () => Model<TModelAttributes, TCreationAttributes>);
// ---
export function SequelizeFilter(model: ModelType, filterable: string[], filter?: string): WhereOptions | undefined {
if (!filter || filter === "") return;
const fields = [];
for (let prop of filterable) {
// rawAttributes works here because of Properties<typeof Model>
// otherwise there would be: Property 'rawAttributes' does not exist on type 'ModelType<any, any>'.
if (model.rawAttributes?.[prop]) {
fields.push({ [prop]: { [Op.substring]: filter } });
}
}
return fields.length ? { [Op.or]: fields } : undefined;
} Edit: There is type |
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.
Sorry for the late reply: Good work 👍
Awesome, thanks for moving this forward :) It seems my initial issues weren't addressed though in regards to Includeables: #868 (comment) Comment here: #835 (comment) It looks like it was acknowledged in the comment above that it should be fixed within Sequelize itself |
Update of #868 with fixed lint errors. #868 (comment)
cc: @divlo