diff --git a/src/Notification.ts b/src/Notification.ts index c62028a6fd..c575a02889 100644 --- a/src/Notification.ts +++ b/src/Notification.ts @@ -1,6 +1,10 @@ import {Observer} from './Observer'; import {Observable} from './Observable'; +function isObserver(v: any | Observer): v is Observer { + return !!v && typeof v.next === 'function' && typeof v.error === 'function' && typeof v.complete === 'function'; +} + export class Notification { hasValue: boolean; @@ -32,8 +36,8 @@ export class Notification { } accept(nextOrObserver: Observer | ((value: T) => void), error?: (err: any) => void, complete?: () => void) { - if (nextOrObserver && typeof (>nextOrObserver).next === 'function') { - return this.observe(>nextOrObserver); + if (isObserver(nextOrObserver)) { + return this.observe(nextOrObserver); } else { return this.do(<(value: T) => void>nextOrObserver, error, complete); }