mongoose-paginate-v2
mongoose-paginate-v2 copied to clipboard
An issue with types on mongoose v5
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
- Install legacy version of
mongoose
(latest is 5.13.14) and latest version ofmongoose-paginate-v2
:yarn add [email protected] mongoose-paginate-v2
- Create a sample file with imports of
mongoose
andmongoose-paginate-v2
:index.ts
:
import { Mongoose } from "mongoose";
import { paginate } from "mongoose-paginate-v2";
- Try to transpile that file by using tsc:
> tsc .\index.ts
Expected behavior TSC should transpile the file without returning any type errors.
Screenshots
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 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 that link isn't working. What's the specific version to use?
@jdhiro This seems to be the latest one. Can you try it. https://github.com/DefinitelyTyped/DefinitelyTyped/tree/1948b8888159b85e0771567b23ff6f279b0a7866
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
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: @.***>
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).
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.
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: @.***>
// tsconfig.json
skipLibCheck: true
This can avoid the build error but I don't think that's a solution.