Skip to content
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

types: improve the typing of FilterQuery<T> type to prevent it from only getting typed to any #14436

Merged
merged 1 commit into from Mar 18, 2024

Conversation

vkarpov15
Copy link
Collaborator

Re: #14398
Fix #14397

@FaizBShah WDYT?

Summary

#14398 but with a couple of changes:

  1. Avoided changing FilterQuery<RawDocType> back to FilterQuery<DocType> for everything but getFilter() and getQuery(). For some reason, tests fail without that
  2. Fixes for the [Types] Adjusments to ApplyBasicQueryCasting (ff2bf3e8b3abe0e09a523465e5db8743083702b9) break FilterQueries for generic types #11964 test. The fact that we had to change that test was concerning, but after diving down the rabbit hole I'm convinced the [Types] Adjusments to ApplyBasicQueryCasting (ff2bf3e8b3abe0e09a523465e5db8743083702b9) break FilterQueries for generic types #11964 test is just incorrect and will never work unless FilterQuery types to any. Here's a couple of TypeScript playground examples demonstrating the issue, which is that with class Repository<T>, there's no way to type T so that T excludes { id: never }, and WithId<{ id: never }> still types to {id: never}.

Examples

@FaizBShah
Copy link
Contributor

Yeah, this looks good to me!! Even I personally didn't liked changing RawDocType to to DocType everywhere, but did it because I thought maybe some types might fail, but this soln. looks cleaner. And yes, the test was incorrect because it was written with the assumption that id will never be able to be never. LGTM!!

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though i am not really involved with the semantics of these types.

@@ -307,20 +313,34 @@ function autoTypedQuery() {
}

function gh11964() {
class Repository<T extends { id: string }> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can make / have a helper that is a BasicPojoDocument for easy / quick / shared access

test/types/queries.test.ts Show resolved Hide resolved
@vkarpov15 vkarpov15 added this to the 8.2.3 milestone Mar 18, 2024
@vkarpov15 vkarpov15 merged commit e3f3205 into master Mar 18, 2024
5 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14398 branch March 19, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter query Condition type might as well be any
3 participants