aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.
https://www.npmjs.com/package/mongoose-paginate-v2
MIT License
500 stars 91 forks source link

Inconsistent declaration of Query #220

Closed twibster closed 1 month ago

twibster commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

Thanks for the fix. @twibster