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(query): fix usage of "RawDocType" where "DocType" should be passed #14737

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

hasezoey
Copy link
Collaborator

Summary

This PR fixes find and fineOne overload returns where DocType should be used over RawDocType, at least to my understanding, this had already been done partially in fa0bc8d, but not for findOne so this could be forward-ported.

The generics for context (as of 7.7.0):

class Query<ResultType, DocType, THelpers = {}, RawDocType = DocType, QueryOp = 'find'> implements SessionOperation {

Without this change using and expecting assignability would result in a error like in typegoose:

Type 'QueryHelperThis<typeof QueryMethodsClass, FindHelpers, DocumentType<QueryMethodsClass, FindHelpers>>' is not assignable to type 'QueryWithHelpers<DocumentType<QueryMethodsClass, FindHelpers> | null, DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, DocumentType<...>, "find">'.
  Type 'QueryHelperThis<typeof QueryMethodsClass, FindHelpers, DocumentType<QueryMethodsClass, FindHelpers>>' is not assignable to type 'Query<DocumentType<QueryMethodsClass, FindHelpers> | null, DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, DocumentType<...>, "find">'.
    The types returned by 'find(...)' are incompatible between these types.
      Type 'QueryWithHelpers<QueryMethodsClass[], DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, QueryMethodsClass, "find">' is not assignable to type 'QueryWithHelpers<DocumentType<QueryMethodsClass, FindHelpers>[], DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, DocumentType<...>, "find">'.
        Type 'QueryWithHelpers<QueryMethodsClass[], DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, QueryMethodsClass, "find">' is not assignable to type 'Query<DocumentType<QueryMethodsClass, FindHelpers>[], DocumentType<QueryMethodsClass, FindHelpers>, FindHelpers, DocumentType<...>, "find">'.
          The types returned by 'exec()' are incompatible between these types.
            Type 'Promise<QueryMethodsClass[]>' is not assignable to type 'Promise<DocumentType<QueryMethodsClass, FindHelpers>[]>'.
              Type 'QueryMethodsClass[]' is not assignable to type 'DocumentType<QueryMethodsClass, FindHelpers>[]'.
                Type 'QueryMethodsClass' is not assignable to type 'DocumentType<QueryMethodsClass, FindHelpers>'.
                  Type 'QueryMethodsClass' is missing the following properties from type 'Document<unknown, FindHelpers, QueryMethodsClass>': $assertPopulated, $clone, $getAllSubdocs, $ignore, and 47 more.ts(2322)

no change was necessary (to not result in a type error) before mongoose 7.6.6 and no change was necessary in mongoose 8.0.0 and up

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Jul 10, 2024
@hasezoey hasezoey requested a review from vkarpov15 July 10, 2024 11:21
@vkarpov15 vkarpov15 added this to the 7.8.0 milestone Jul 11, 2024
@vkarpov15 vkarpov15 merged commit 0c65a53 into Automattic:7.x Jul 11, 2024
3 checks passed
@hasezoey hasezoey deleted the 7xFixQueryFind branch July 11, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants