-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
[@strapi/database]: Add missing WhereParams attributes to the type definition #13290
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
Conversation
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 opening this PR, only one question!
|
The only thing I noticed that's still not supported even with the updated types is nested where clauses that filter on relations. In my application I have a usecase like this: type ResearchCollection = {
id: number;
title: string;
slug: string;
date: string;
created_at: string;
updated_at: string;
published_at: string;
created_by_id: string;
updated_by_id: string;
categories: {
id: number;
category: string;
}[];
communities: {
id: number;
community: string;
}[];
}now using this type definition for one of the collection by overriding the AllTypes in interface AllTypes {
'api::research.research': ResearchCollection;
}If now I want to write a where clause that filters on the collection {
where: {
categories: {
id: SOME_ID
}
}
}which still throws a type error as of now. Any ideas how that should be handled? |
|
Hey, concerning your last point about nested where clauses: I'm currently writing the first version of the typings for the content types. Once we'll have that, we'll be able to refactor typings for the entity service & such tools. I think we can wait a bit for them before diving into early solutions. What do you think? |
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.
LGTM
Codecov Report
@@ Coverage Diff @@
## features/typescript #13290 +/- ##
=======================================================
- Coverage 48.23% 48.20% -0.04%
=======================================================
Files 245 251 +6
Lines 8776 8948 +172
Branches 1956 2008 +52
=======================================================
+ Hits 4233 4313 +80
- Misses 3732 3817 +85
- Partials 811 818 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Yeah, we can wait a bit. |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/strapi-v4-2-0-fourth-beta-for-typescript-support/18869/1 |
Fixes #13287
As described in the mentioned issue. Most of the parameters listed in the docs are missing. Only the and, or and not was added so far.
This PR adds all missing attributes so that the typing for the WhereParams is correct.
What does it do?
It adds the filter parameters
$eq,$ne,$in, and all others while supporting the nested structure.Why is it needed?
As of now the typescript complirer throws an error on the where clause. Example:
this was not possible, because
$gteand$ltwhere both within the missing attributes.How to test it?
Use the code example from above and try out valid queries. Now the types will be correct.
Related issue(s)/PR(s)
#13287