types(query): make FilterQuery
props resolve to any
for generics support
#14510
+26
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #14473
Re: #14459
Tagging @FaizBShah @sderrow re: #14436, #14397
Summary
It looks like the major reason for
FilterQuery<T>
setting all props toany
is because TypeScript disallows setting an object with a concrete type to an abstract type. This includes generic function parameters, like calling a function withFilterQuery<>
as a parameter whereFilterQuery<>
depends on the generic. For example:From this SO answer: "Never assign a concrete type to a generic type parameter, consider it as read-only!". That includes calling a function with arguments that rely on the generic type parameter. This restriction makes sense because of
never
This whole "generic function for wrapping Mongoose model functions" pattern isn't one that I would personally use, but it seems to be sufficiently common that we've gotten 3 distinct bug reports related to this change #14459, #14473, #14462
Examples