From 7bb9e3729a23e845a68532f554808fb52decfacb Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 4 Jan 2022 12:15:54 -0500 Subject: [PATCH] fix(gridfs): make `GridFSBucketWriteStream.prototype.end()` return `this` for compat with @types/node@17.0.6 (#3088) --- src/gridfs/upload.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index 26e9a4ad1c..5c51c5e810 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -172,21 +172,21 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable * @param encoding - Optional encoding for the buffer * @param callback - Function to call when all files and chunks have been persisted to MongoDB */ - end(): void; - end(chunk: Buffer): void; - end(callback: Callback): void; - end(chunk: Buffer, callback: Callback): void; - end(chunk: Buffer, encoding: BufferEncoding): void; + end(): this; + end(chunk: Buffer): this; + end(callback: Callback): this; + end(chunk: Buffer, callback: Callback): this; + end(chunk: Buffer, encoding: BufferEncoding): this; end( chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback - ): void; + ): this; end( chunkOrCallback?: Buffer | Callback, encodingOrCallback?: BufferEncoding | Callback, callback?: Callback - ): void { + ): this { const chunk = typeof chunkOrCallback === 'function' ? undefined : chunkOrCallback; const encoding = typeof encodingOrCallback === 'function' ? undefined : encodingOrCallback; callback = @@ -196,7 +196,7 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable ? encodingOrCallback : callback; - if (checkAborted(this, callback)) return; + if (checkAborted(this, callback)) return this; this.state.streamEnd = true; @@ -208,12 +208,14 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable if (!chunk) { waitForIndexes(this, () => !!writeRemnant(this)); - return; + return this; } this.write(chunk, encoding, () => { writeRemnant(this); }); + + return this; } }