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

Inconsistent declaration of Query #220

Closed
twibster opened this issue Sep 25, 2024 · 6 comments
Closed

Inconsistent declaration of Query #220

twibster opened this issue Sep 25, 2024 · 6 comments

Comments

@twibster
Copy link
Contributor

twibster commented Sep 25, 2024

Describe the bug
On the latest version of mongoose (8.6.3), There is a difference in RawDocType parameter type (unknown) in the Query class in mongoose.d.ts:

class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TInstanceMethods = Record<string, never>>

and Query interface in index.d.ts (Ref to DocType) from the package here:

interface Query<ResultType, DocType, THelpers = NonNullable<unknown>, RawDocType = DocType, QueryOp = 'find', TInstanceMethods = Record<string, never>>

which is causing an inconsistent declaration error in TypeScript

To Reproduce
1- building the application or whatever using the package and mongoose

Expected behavior
A matching declaration of Query in the package and in mongoose

@twibster
Copy link
Contributor Author

A solution to this problem is replacing the type parameter for RawDocType from DocType to unkown to match mongoose Query declaration

interface Query<
    ResultType,
    DocType,
    THelpers = NonNullable<unknown>,
    RawDocType = unknown,
    QueryOp = 'find',
    TInstanceMethods = Record<string, never>,
  > {
    paginate<O extends PaginateOptions>(
      options?: O
    ): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, O>>>
    paginate<UserType = ResultType, O extends PaginateOptions = PaginateOptions>(
      options?: O
    ): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, O>>>
    paginate<UserType = ResultType>(
      options?: PaginateOptions
    ): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, PaginateOptions>>>
  }

@twibster
Copy link
Contributor Author

twibster commented Sep 26, 2024

also we can ignore the error by placing the following line before the interface:

// @ts-expect-error overwriting of mongoose Query interface

as in #221

@aravindnc
Copy link
Owner

Thanks for the fix. @twibster

@Clashsoft
Copy link

This is still not fixed as of 1.9.0. The @ts-ignore commit does not work because the error still shows in the mongoose declaration:

node_modules/.pnpm/mongoose@8.9.3/node_modules/mongoose/types/query.d.ts:241:9 - error TS2428: All declarations of 'Query' must have identical type parameters.

241   class Query<ResultType, DocType, THelpers = {}, RawDocType = unknown, QueryOp = 'find', TDocOverrides = Record<string, never>> implements SessionOperation {
            ~~~~~

@aravindnc
Copy link
Owner

@Clashsoft Please see if it works with v1.8.5

@Clashsoft
Copy link

Nope.

node_modules/.pnpm/mongoose-paginate-v2@1.8.5/node_modules/mongoose-paginate-v2/index.d.ts:132:13 - error TS2428: All declarations of 'Query' must have identical type parameters.

132   interface Query<
                ~~~~~

node_modules/.pnpm/mongoose@8.9.3/node_modules/mongoose/types/query.d.ts:241:9 - error TS2428: All declarations of 'Query' must have identical type parameters.

241   class Query<
            ~~~~~

mongoose-paginate-v2

  interface Query<
    ResultType,
    DocType,
    THelpers = NonNullable<unknown>,
    RawDocType = DocType,
    QueryOp = 'find',
    TInstanceMethods = Record<string, never>,
  > {

mongoose

  class Query<
    ResultType,
    DocType,
    THelpers = {},
    RawDocType = unknown,
    QueryOp = 'find',
    TDocOverrides = Record<string, never>
  > implements SessionOperation {

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

No branches or pull requests

3 participants