Skip to content

Commit

Permalink
fix(Subscription): Return Empty when teardown === null (ReactiveX#4575)
Browse files Browse the repository at this point in the history
* 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 BioPhoton committed May 15, 2019
1 parent c5566f5 commit 0a23674
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/internal/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.');
}
}
Expand Down

0 comments on commit 0a23674

Please sign in to comment.