mongoose-paginate-v2 icon indicating copy to clipboard operation
mongoose-paginate-v2 copied to clipboard

An issue with types on mongoose v5

Open LosTigeros opened this issue 2 years ago • 9 comments

Describe the bug Hey, that's not really a bug, but some type errors. To be exact, these:

> tsc
node_modules/mongoose-paginate-v2/index.d.ts:23:35 - error TS2694: Namespace '"node_modules/@types/mongodb/index"' has no exported member 'CollationOptions'. 

23     collation?: import('mongodb').CollationOptions | undefined;
                                     ~~~~~~~~~~~~~~~~

node_modules/mongoose-paginate-v2/index.d.ts:74:7 - error TS2304: Cannot find name 'HydratedDocument'.

74     : HydratedDocument<T, TMethods, TVirtuals>;
         ~~~~~~~~~~~~~~~~


Found 2 errors.

To Reproduce

  1. Install legacy version of mongoose (latest is 5.13.14) and latest version of mongoose-paginate-v2: yarn add [email protected] mongoose-paginate-v2
  2. Create a sample file with imports of mongoose and mongoose-paginate-v2: index.ts:
import { Mongoose } from "mongoose";
import { paginate } from "mongoose-paginate-v2";

  1. Try to transpile that file by using tsc: > tsc .\index.ts

Expected behavior TSC should transpile the file without returning any type errors.

Screenshots image

Desktop (please complete the following information): Not needed

Smartphone (please complete the following information): Not needed

Additional context If it helps you with anything, I'm using yarn instead of npm.

LosTigeros avatar Apr 12 '22 18:04 LosTigeros

@LosTigeros Please use below version for Mongoose 5. https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mongoose-paginate-v2

Let me know if this helps.

aravindnc avatar Apr 19 '22 19:04 aravindnc

@aravindnc that link isn't working. What's the specific version to use?

jdhiro avatar Apr 28 '22 21:04 jdhiro

@jdhiro This seems to be the latest one. Can you try it. https://github.com/DefinitelyTyped/DefinitelyTyped/tree/1948b8888159b85e0771567b23ff6f279b0a7866

aravindnc avatar Apr 29 '22 01:04 aravindnc

After installing it, I'm getting a lot of these:

error TS2717: Subsequent property declarations must have the same type. 
error TS2374: Duplicate index signature for type 'string'.
error TS2300: Duplicate identifier 'PaginateDocument'.

log.txt

So this is not a solution

LosTigeros avatar Apr 29 '22 06:04 LosTigeros

You need to install old version of the plugin to work. https://www.npmjs.com/package/mongoose-paginate-v2/v/1.5.0

Try above version or below for the time being.

Regards,Aravind NC

On Friday, 29 April, 2022, 11:52:51 am IST, Patryk L. ***@***.***> wrote:  

After installing it, I'm getting a lot of these: error TS2717: Subsequent property declarations must have the same type. error TS2374: Duplicate index signature for type 'string'. error TS2300: Duplicate identifier 'PaginateDocument'.

So this is not a solution

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

aravindnc avatar Apr 29 '22 07:04 aravindnc

I created that issue because I wanted to use the latest version of this package. It doesn't say anywhere that >= 1.6.0 is not compatible with v5 anymore. If this issue won't be fixed, please at least state somewhere that, mongoose-paginate-v2 >=1.6.0 is not compatible with legacy version of mongoose (v5).

LosTigeros avatar Apr 29 '22 08:04 LosTigeros

I had put off upgrading to the latest version of mongoose, and hence this library, because I was getting a ton of type errors when trying to update...

Until I realized that my @types/node was @10 instead of @16. Updating that one thing got rid of almost all of my type errors with both Mongoose and this package. YMMV.

jdhiro avatar Jul 16 '22 01:07 jdhiro

Thanks for pointing this out.

There is a writeup already in the readme section. Prior to version 1.5.0, types need to be installed from DefinitelyTyped.

But, we are not sure how the ts version got removed from DefinitelyTyped which caused the issue. I will try some alternative for supporting mongoose v5.

On Friday, 29 April, 2022, 01:50:37 pm IST, Patryk L. ***@***.***> wrote:  

I created that issue because I wanted to use the latest version of this package. It doesn't say anywhere that >= 1.6.0 is not compatible with v5 anymore. If this issue won't be fixed, please at least state somewhere that, mongoose-paginate-v2 >=1.6.0 is not compatible with legacy version of mongoose (v5).

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

aravindnc avatar Oct 11 '22 07:10 aravindnc

// tsconfig.json
skipLibCheck: true

This can avoid the build error but I don't think that's a solution.

nothingrealhappen avatar Feb 08 '23 09:02 nothingrealhappen