Skip to content
Permalink
Browse files

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
  • Loading branch information...
ChristianKohler authored and benlesh committed May 10, 2019
1 parent 126d2b6 commit ffc4e688fa83cb44bff7e5deacc4063f8ea1e2fa
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/internal/Subscription.ts
@@ -130,6 +130,11 @@ export class Subscription implements SubscriptionLike {
*/
add(teardown: TeardownLogic): Subscription {
let subscription = (<Subscription>teardown);

if (!(<any>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 (!(<any>teardown)) {
return Subscription.EMPTY;
}
throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.');
}
}

0 comments on commit ffc4e68

Please sign in to comment.
You can’t perform that action at this time.