multer-gridfs-storage
multer-gridfs-storage copied to clipboard
Deprecated @types/mongodb package causes error
Describe the bug
multer-gridfs-storage
uses the deprecated @types/mongodb
package as a dependency. There are conflicts with the mongodb
package in version >= 5:
node_modules/multer-gridfs-storage/node_modules/@types/mongodb/index.d.ts:58:74 - error TS2724: '"bson"' has no exported member named 'ObjectID'. Did you mean 'ObjectId'?
58 export { Binary, DBRef, Decimal128, Double, Int32, Long, MaxKey, MinKey, ObjectID, ObjectId, Timestamp } from "bson";
~~~~~~~~
node_modules/bson/bson.d.ts:918:22
918 export declare class ObjectId extends BSONValue {
~~~~~~~~
'ObjectId' is declared here.
Found 1 error in node_modules/multer-gridfs-storage/node_modules/@types/mongodb/index.d.ts:58
Environment
-
I'm using
multer-gridfs-storage
package version 5.0.2 withmongodb
package version 5.0.1 -
My installed MongoDb version is 6.0.1
-
I have Multer 1.4.5-lts.1 installed to upload files
-
The Node version used to run the code is 16.17.0
- I'm using Mongoose connection objects to create storage instances. The Mongoose version installed is 6.9.1
To Reproduce Integrate the above packages into any project and try to build the project.
Expected behavior
Since mongodb now comes with its own types, the deprecated @types/mongodb
package can be dispensed with altogether.
I can confirm that the @types/mongodb
package has it's problem. For me, it is from the TSchema generic and some others mentioned below.
node_modules/@types/mongodb/index.d.ts:58:74 - error TS2724: '"bson"' has no exported member named 'ObjectID'. Did you mean 'ObjectId'?
58 export { Binary, DBRef, Decimal128, Double, Int32, Long, MaxKey, MinKey, ObjectID, ObjectId, Timestamp } from "bson";
~~~~~~~~
node_modules/bson/bson.d.ts:975:22
975 export declare class ObjectId extends BSONValue {
~~~~~~~~
'ObjectId' is declared here.
node_modules/@types/mongodb/index.d.ts:1198:45 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1198 callback?: MongoCallback<Collection<TSchema>>,
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1196:16
1196 collection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1199:19 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1199 ): Collection<TSchema>;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1196:16
1196 collection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1203:45 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1203 callback?: MongoCallback<Collection<TSchema>>,
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1200:16
1200 collection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1204:19 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1204 ): Collection<TSchema>;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1200:16
1200 collection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1244:96 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1244 createCollection<TSchema = DefaultSchema>(name: string, callback: MongoCallback<Collection<TSchema>>): void;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1244:22
1244 createCollection<TSchema = DefaultSchema>(name: string, callback: MongoCallback<Collection<TSchema>>): void;
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1248:27 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1248 ): Promise<Collection<TSchema>>;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1245:22
1245 createCollection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1252:44 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1252 callback: MongoCallback<Collection<TSchema>>,
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1249:22
1249 createCollection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1384:44 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1384 callback: MongoCallback<Collection<TSchema>>,
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1381:22
1381 renameCollection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1390:27 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1390 ): Promise<Collection<TSchema>>;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1386:22
1386 renameCollection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:1395:44 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ [key: string]: any; }'.
1395 callback: MongoCallback<Collection<TSchema>>,
~~~~~~~
node_modules/@types/mongodb/index.d.ts:1391:22
1391 renameCollection<TSchema = DefaultSchema>(
~~~~~~~~~~~~~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:2559:21 - error TS2344: Type 'T' does not satisfy the constraint '{ [key: string]: any; }'.
2559 ): ChangeStream<T>;
~
node_modules/@types/mongodb/index.d.ts:2556:11
2556 watch<T = TSchema>(
~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:2560:111 - error TS2344: Type 'T' does not satisfy the constraint '{ [key: string]: any; }'.
2560 watch<T = TSchema>(options?: ChangeStreamOptions & { session?: ClientSession | undefined }): ChangeStream<T>;
~
node_modules/@types/mongodb/index.d.ts:2560:11
2560 watch<T = TSchema>(options?: ChangeStreamOptions & { session?: ClientSession | undefined }): ChangeStream<T>;
~~~~~~~~~~~
This type parameter might need an `extends { [key: string]: any; }` constraint.
node_modules/@types/mongodb/index.d.ts:2911:30 - error TS2344: Type 'TSchema' does not satisfy the constraint '{ _id?: any; }'.
2911 document: OptionalId<TSchema>;
~~~~~~~
node_modules/@types/mongodb/index.d.ts:2909:41
2909 export type BulkWriteInsertOneOperation<TSchema> = {
~~~~~~~
This type parameter might need an `extends { _id?: any; }` constraint.
Found 14 errors in the same file, starting at: node_modules/@types/mongodb/index.d.ts:58
Environment:
- node version:
16.14.2
- yarn version:
1.22.18
-
package.json
:{ "license": "MIT", "scripts": { "build": "tsc" }, "dependencies": { "multer-gridfs-storage": "^5.0.2" }, "devDependencies": { "@tsconfig/node16": "^1.0.4", "typescript": "^5.1.3" } }
-
tsconfig.json
:{ "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "skipLibCheck": false, }, "files": [ "index.ts" ] }
Step to reproduce:
-
RUN
yarn && yarn build
Workaround
Edit the tsconfig.json
file and set compilerOptions.skipLibCheck
to true:
{
"compilerOptions": {
"skipLibCheck": true,
}
}
To workaround this case, I use the default configurations provided by the
@tsconfig/node16
package which includecompilerOptions.skipLibCheck
default totrue
. This will enable me to build my project despite errors in the library's typings.
why is @types/mongodb package not updated to latest yet?