From 7d8f21a63b9fd1c617aa85a8679be251461d9f39 Mon Sep 17 00:00:00 2001 From: Christian Kohler Date: Mon, 18 Feb 2019 14:25:36 +0100 Subject: [PATCH 1/2] 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. --- 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..df5a91d02f 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.'); } } From c4a8bc0a6a6f26ceac4cfc0cd7562c48c2040f62 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 18 Feb 2019 14:53:45 +0100 Subject: [PATCH 2/2] fix(Subscription): tslint errors --- src/internal/Subscription.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/Subscription.ts b/src/internal/Subscription.ts index df5a91d02f..1a07ffa508 100644 --- a/src/internal/Subscription.ts +++ b/src/internal/Subscription.ts @@ -130,11 +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);