diff --git a/src/storage/implementation/observer.ts b/src/storage/implementation/observer.ts index c781727b184..3b240f35609 100644 --- a/src/storage/implementation/observer.ts +++ b/src/storage/implementation/observer.ts @@ -46,10 +46,14 @@ export class Observer { this.error = opt_error || null; this.complete = opt_complete || null; } else { - const observer = nextOrObserver as {[name: string]: null}; - this.next = observer['next'] as (NextFn | null); - this.error = observer['error'] as (ErrorFn | null); - this.complete = observer['complete'] as (CompleteFn | null); + const observer = nextOrObserver as { + next?: NextFn | null; + error?: ErrorFn | null; + complete?: CompleteFn | null; + }; + this.next = observer.next || null; + this.error = observer.error || null; + this.complete = observer.complete || null; } } } diff --git a/tests/storage/browser/task_test.ts b/tests/storage/browser/task_test.ts index 95ca72e4fcf..a0d429c82f3 100644 --- a/tests/storage/browser/task_test.ts +++ b/tests/storage/browser/task_test.ts @@ -231,6 +231,18 @@ describe("Firebase Storage > Upload Task", () => { }); }); }); + it("Works properly with an observer missing the 'next' method", () => { + const authWrapper = authWrapperWithHandler(fakeServerHandler()); + const task = new UploadTask( + {} as Reference, authWrapper, testLocation, mappings, smallBlob); + return fbsPromise.make((resolve, reject) => { + task.on( + TaskEvent.STATE_CHANGED, { + error: err => { assert.fail('Unexpected upload failure'); }, + complete: () => { resolve(null); } + }); + }); + }); function runNormalUploadTest(blob: FbsBlob): Promise { const authWrapper = authWrapperWithHandler(fakeServerHandler());