From ffc4e688fa83cb44bff7e5deacc4063f8ea1e2fa Mon Sep 17 00:00:00 2001 From: Christian Kohler Date: Fri, 10 May 2019 02:14:23 +0200 Subject: [PATCH] fix(Subscription): Return Empty when teardown === null (#4575) * fix(Subscription): Return Empty when teardown === null `typeof teardown` returns object when null. It breaks later when rxjs tries to access the closed property. The commit fixes that by first checking for null/undefined. * fix(Subscription): tslint errors --- src/internal/Subscription.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/internal/Subscription.ts b/src/internal/Subscription.ts index 0f1906a27e..1a07ffa508 100644 --- a/src/internal/Subscription.ts +++ b/src/internal/Subscription.ts @@ -130,6 +130,11 @@ export class Subscription implements SubscriptionLike { */ add(teardown: TeardownLogic): Subscription { let subscription = (teardown); + + if (!(teardown)) { + return Subscription.EMPTY; + } + switch (typeof teardown) { case 'function': subscription = new Subscription(<(() => void)>teardown); @@ -147,9 +152,6 @@ export class Subscription implements SubscriptionLike { } break; default: { - if (!(teardown)) { - return Subscription.EMPTY; - } throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } }