Replies: 1 comment 1 reply
-
At first glance it looks like Mongoose's types may be wrong. Maybe replace this: // snippit from query.d.ts
find(
filter: FilterQuery<DocType>,
projection?: ProjectionType<DocType> | null,
options?: QueryOptions<DocType> | null
): QueryWithHelpers<Array<DocType>, DocType, THelpers, RawDocType, 'find'>; with this?
You're right that |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am currently trying to fix typegoose/typegoose#870, but i got confused because of the 3 types mentioned in the title, for example:
Model.find({})
's return type is:(basically
Query<Document<>[], Document<>, {}, ActualRawObject, QueryOperation>
)but doing a additional
.find
(because it is possible and has the closest types to the query helpers) likeModel.find({}).find({})
has actually the wrong typing for the suggestions in{}
(for the second.find
), because the second.find
uses theDocType
parameter of theQuery<>
type, but that is set to aDocument<>
, which makes it suggest function likepopulate
as a value:in addition, fixing it in typegoose by replacing the current
mongoose.QueryWithHelpers<Document<>, Document<>>
withmongoose.QueryWithHelpers<Document<>, RawClassType>
actually breaks query helper functions which returnthis.find
(and other functions) because those functions all return the genericDocType
in theQuery<>
'sResultType
generic slot, instead of theResultType
generic. current code snippit:(notice the
QueryWithHelpers<DocType[], DocType>
)where as the
Model
's functions return aResultType
in theResultType
generic slot, snippit:(notice the
QueryWithHelpers<ResultDoc[], ResultDoc>
)so my question is: am i doing things wrong, or are the mongoose types wrong?
mongoose 1bfcdf6 and 8.0.0 (even in 7.6.4)
Beta Was this translation helpful? Give feedback.
All reactions