devconcept / multer-gridfs-storage

🍃 GridFS storage engine for Multer to store uploaded files directly to MongoDb
MIT License
237 stars 67 forks source link

Deprecated @types/mongodb package causes error #554

Open kaihaase opened 1 year ago

kaihaase commented 1 year ago

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

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.

jordiyapz commented 1 year ago

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:

Step to reproduce:

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 include compilerOptions.skipLibCheck default to true. This will enable me to build my project despite errors in the library's typings.

alanpurple commented 8 months ago

why is @types/mongodb package not updated to latest yet?