Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3559

GridFSBucketWriteStream' is not assignable to parameter of type 'WritableStream'

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 4.1.2
    • Affects Version/s: 4.1.0
    • Component/s: TypeScript
    • Labels:
    • Not Needed

      What problem are you facing?

      While upgrading drivers from 3.6.11 to 4.1.0 I get a TS compiling error that I can't resolve:

      error TS2345: Argument of type 'GridFSBucketWriteStream' is not assignable to parameter of type 'WritableStream'.
        Types of property 'write' are incompatible.
          Type '{ (chunk: Buffer): boolean; (chunk: Buffer, callback: Callback<void>): boolean; (chunk: Buffer, encoding: BufferEncoding | undefined): boolean; (chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<...>): boolean; }' is not assignable to type '{ (buffer: string | Uint8Array, cb?: ((err?: Error | null | undefined) => void) | undefined): boolean; (str: string, encoding?: BufferEncoding | undefined, cb?: ((err?: Error | ... 1 more ... | undefined) => void) | undefined): boolean; }'.
            Types of parameters 'chunk' and 'str' are incompatible.
              Type 'string' is not assignable to type 'Buffer'.95       .pipe(uploadStream)
      

      With the previous version (3.6.11) the software compiles and runs smoothly

      What driver and relevant dependency versions are you using?

      I went from version 3.6.11 to 4.1.0

      Steps to reproduce?

       Try to build di TS code:

       

       

      Text version:

      import { Readable } from "stream";
      import { GridFSBucket } from "mongodb";

      export const storeDocumentPromise = (
      bucket: GridFSBucket,
      docName: string,
      trxid: string,
      base64data: any,
      contentType: any
      ) => {
      constreadable = newReadable();
      readable._read = functionnoop() {};
      readable.push(base64data);
      readable.push(null);

      constoptions = {
      metadata:

      { name:docName, trxid:trxid, }

      ,
      contentType,
      };

      constuploadStream = bucket.openUploadStream(docName, options);
      constuploadStreamId = uploadStream.id;

      constp = newPromise<string>((resolve, reject) => {
      readable
      .pipe(uploadStream)
      .on("error", function (error: Error)

      { reject(error); }

      )
      .on("finish", function ()

      { constid = uploadStreamId.toString(); resolve(id); }

      );
      });

      returnp;
      };
       

            Assignee:
            daria.pardue@mongodb.com Daria Pardue
            Reporter:
            eros.valzasina@gmail.com Eros Valzasina
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: