diff --git a/src/CoreOperators.ts b/src/CoreOperators.ts index 60e595de1a1..86e79618b36 100644 --- a/src/CoreOperators.ts +++ b/src/CoreOperators.ts @@ -35,9 +35,9 @@ export interface CoreOperators { projectResult?: (x: T, y: any, ix: number, iy: number) => R, concurrent?: number) => Observable; flatMapTo?: (observable: Observable, projectResult?: (x: T, y: any, ix: number, iy: number) => R, concurrent?: number) => Observable; - groupBy?: (keySelector: (value: T) => string, + groupBy?: (keySelector: (value: T) => string, elementSelector?: (value: T) => R, - durationSelector?: (group: GroupedObservable) => Observable) => Observable>; + durationSelector?: (group: GroupedObservable) => Observable) => Observable>; ignoreElements?: () => Observable; last?: (predicate?: (value: T, index: number) => boolean, resultSelector?: (value: T, index: number) => R, diff --git a/src/Notification.ts b/src/Notification.ts index da647acd3f3..c62028a6fd7 100644 --- a/src/Notification.ts +++ b/src/Notification.ts @@ -47,7 +47,7 @@ export class Notification { case 'E': return Observable.throw(this.exception); case 'C': - return Observable.empty(); + return Observable.empty(); } } diff --git a/src/Observable.ts b/src/Observable.ts index dca6a957d7e..9df3e491002 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -21,7 +21,7 @@ import {rxSubscriber} from'./symbol/rxSubscriber'; export class Observable implements CoreOperators { source: Observable; operator: Operator; - _isScalar: boolean = false; + _isScalar = false; /** * @constructor @@ -30,7 +30,7 @@ export class Observable implements CoreOperators { * can be `next`ed, or an `error` method can be called to raise an error, or `complete` can be called to notify * of a successful completion. */ - constructor(subscribe?: (subscriber: Subscriber) => Subscription|Function|void) { + constructor(subscribe?: (subscriber: Subscriber | Function) => Subscription) { if (subscribe) { this._subscribe = subscribe; } @@ -45,8 +45,8 @@ export class Observable implements CoreOperators { * @returns {Observable} a new cold observable * @description creates a new cold Observable by calling the Observable constructor */ - static create: Function = (subscribe?: (subscriber: Subscriber) => Subscription|Function|void) => { - return new Observable(subscribe); + static create: Function = (subscribe?: (subscriber: Subscriber | Function) => Subscription) => { + return new Observable(subscribe); }; /** @@ -56,8 +56,8 @@ export class Observable implements CoreOperators { * @description creates a new Observable, with this Observable as the source, and the passed * operator defined as the new observable's operator. */ - lift(operator: Operator): Observable { - const observable = new Observable(); + lift(operator: Operator): Observable { + const observable = new Observable(); observable.source = this; observable.operator = operator; return observable; @@ -98,7 +98,7 @@ export class Observable implements CoreOperators { subscriber = new Subscriber(> observerOrNext); } } else { - const next = <((x?) => void)> observerOrNext; + const next = <((x?: any) => void)> observerOrNext; subscriber = Subscriber.create(next, error, complete); } @@ -115,7 +115,7 @@ export class Observable implements CoreOperators { * @returns {Promise} a promise that either resolves on observable completion or * rejects with the handled error */ - forEach(next: (value: T) => void, thisArg: any, PromiseCtor?: PromiseConstructor): Promise { + forEach(next: (value: T) => void, thisArg: any, PromiseCtor?: PromiseConstructor): Promise { if (!PromiseCtor) { if (root.Rx && root.Rx.config && root.Rx.config.Promise) { PromiseCtor = root.Rx.config.Promise; @@ -128,7 +128,7 @@ export class Observable implements CoreOperators { throw new Error('no Promise impl found'); } - let nextHandler; + let nextHandler: any; if (thisArg) { nextHandler = function nextHandlerFn(value: any): void { @@ -141,17 +141,17 @@ export class Observable implements CoreOperators { nextHandler = next; } - const promiseCallback = function promiseCallbackFn(resolve, reject) { + const promiseCallback = function promiseCallbackFn(resolve: Function, reject: Function) { const { source, nextHandler } = promiseCallbackFn; source.subscribe(nextHandler, reject, resolve); }; (promiseCallback).source = this; (promiseCallback).nextHandler = nextHandler; - return new PromiseCtor(promiseCallback); + return new PromiseCtor(promiseCallback); } - _subscribe(subscriber: Subscriber): Subscription | Function | void { + _subscribe(subscriber: Subscriber): Subscription | Function | any { return this.source._subscribe(this.operator.call(subscriber)); } @@ -216,9 +216,9 @@ export class Observable implements CoreOperators { projectResult?: (x: T, y: any, ix: number, iy: number) => R, concurrent?: number) => Observable; flatMapTo: (observable: Observable, projectResult?: (x: T, y: any, ix: number, iy: number) => R, concurrent?: number) => Observable; - groupBy: (keySelector: (value: T) => string, + groupBy: (keySelector: (value: T) => string, elementSelector?: (value: T) => R, - durationSelector?: (group: GroupedObservable) => Observable) => Observable>; + durationSelector?: (group: GroupedObservable) => Observable) => Observable>; ignoreElements: () => Observable; inspect: (notifier: Observable) => Observable; inspectTime: (delay: number, scheduler?: Scheduler) => Observable; diff --git a/src/Operator.ts b/src/Operator.ts index cd87f61895c..3f09af03836 100644 --- a/src/Operator.ts +++ b/src/Operator.ts @@ -6,5 +6,5 @@ export interface Operator { } export function defaultCallFn(observer: Observer): Observer { - return new Subscriber(observer); + return new Subscriber(observer); } diff --git a/src/Scheduler.ts b/src/Scheduler.ts index dff36f50993..25cded908b2 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -3,9 +3,9 @@ import {Action} from './scheduler/Action'; export interface Scheduler { now(): number; - schedule(work: (state?: any) => Subscription|void, delay?: number, state?: any): Subscription; + schedule(work: (state?: any) => Subscription | void, delay?: number, state?: any): Subscription; flush(): void; actions: Action[]; scheduled: boolean; active: boolean; -} \ No newline at end of file +} diff --git a/src/Subject.ts b/src/Subject.ts index da84bb05e1e..ea00b79fc4a 100644 --- a/src/Subject.ts +++ b/src/Subject.ts @@ -26,7 +26,7 @@ export class Subject extends Observable implements Observer, Subscripti } static create(source: Observable, destination: Observer): Subject { - return new BidirectionalSubject(source, destination); + return new BidirectionalSubject(source, destination); } protected destination: Observer; @@ -40,7 +40,7 @@ export class Subject extends Observable implements Observer, Subscripti completeSignal: boolean = false; lift(operator: Operator): Observable { - const subject = new BidirectionalSubject(this, this.destination || this); + const subject = new BidirectionalSubject(this, this.destination || this); subject.operator = operator; return subject; } @@ -63,11 +63,11 @@ export class Subject extends Observable implements Observer, Subscripti return new SubjectSubscription(this, subscriber); } - add(subscription?) { + add(subscription?: Subscription) { subscriptionAdd.call(this, subscription); } - remove(subscription?) { + remove(subscription?: Subscription) { subscriptionRemove.call(this, subscription); } @@ -199,4 +199,4 @@ class BidirectionalSubject extends Subject { _complete(): void { _subscriberComplete.call(this); } -} \ No newline at end of file +} diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 18e0a2e05b6..4e0358400ea 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -37,7 +37,7 @@ export class Subscriber extends Subscription implements Observer { static create(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber { - const subscriber = new Subscriber(); + const subscriber = new Subscriber(); subscriber._next = (typeof next === 'function') && tryOrOnError(next) || noop; subscriber._error = (typeof error === 'function') && error || throwError; subscriber._complete = (typeof complete === 'function') && complete || noop; @@ -58,7 +58,7 @@ export class Subscriber extends Subscription implements Observer { } } - add(sub: Subscription | Function | void): void { + add(sub: Subscription | Function): void { // route add to the shared Subscription if it exists const _subscription = this._subscription; if (_subscription) { @@ -127,4 +127,4 @@ export class Subscriber extends Subscription implements Observer { this.unsubscribe(); } } -} \ No newline at end of file +} diff --git a/src/Subscription.ts b/src/Subscription.ts index 6e4c6129905..ec33d6b5da8 100644 --- a/src/Subscription.ts +++ b/src/Subscription.ts @@ -1,10 +1,10 @@ import {noop} from './util/noop'; export class Subscription { - public static EMPTY: Subscription = (function(empty){ + public static EMPTY: Subscription = (function(empty: any){ empty.isUnsubscribed = true; return empty; - }(new Subscription())); + }(new Subscription())); isUnsubscribed: boolean = false; @@ -47,7 +47,7 @@ export class Subscription { } } - add(subscription: Subscription|Function|void): void { + add(subscription: Subscription | Function): void { // return early if: // 1. the subscription is null // 2. we're attempting to add our this @@ -62,7 +62,7 @@ export class Subscription { switch (typeof subscription) { case 'function': - sub = new Subscription(<(() => void) > subscription); + sub = new Subscription(<(() => void) > subscription); case 'object': if (sub.isUnsubscribed || typeof sub.unsubscribe !== 'function') { break; diff --git a/src/add/operator/exhaust.ts b/src/add/operator/exhaust.ts index ee84fb2de58..dfcec8c4a35 100644 --- a/src/add/operator/exhaust.ts +++ b/src/add/operator/exhaust.ts @@ -2,4 +2,4 @@ import {Observable} from '../../Observable'; import {exhaust} from '../../operator/exhaust'; Observable.prototype.exhaust = exhaust; -export var _void: void; \ No newline at end of file +export var _void: void; diff --git a/src/add/operator/exhaustMap.ts b/src/add/operator/exhaustMap.ts index 420646fe336..2d5a0e9edb3 100644 --- a/src/add/operator/exhaustMap.ts +++ b/src/add/operator/exhaustMap.ts @@ -2,4 +2,4 @@ import {Observable} from '../../Observable'; import {exhaustMap} from '../../operator/exhaustMap'; Observable.prototype.exhaustMap = exhaustMap; -export var _void: void; \ No newline at end of file +export var _void: void; diff --git a/src/add/operator/zip-static.ts b/src/add/operator/zip-static.ts index d8462472478..0f63dc88e75 100644 --- a/src/add/operator/zip-static.ts +++ b/src/add/operator/zip-static.ts @@ -1,5 +1,5 @@ import {Observable} from '../../Observable'; import {zip} from '../../operator/zip-static'; -Observable.zip = zip; +Observable.zip = zip; -export var _void: void; \ No newline at end of file +export var _void: void; diff --git a/src/add/operator/zip.ts b/src/add/operator/zip.ts index 87d896e03de..9d860250d3a 100644 --- a/src/add/operator/zip.ts +++ b/src/add/operator/zip.ts @@ -1,5 +1,5 @@ import {Observable} from '../../Observable'; -import {zipProto} from '../../operator/zip'; -Observable.prototype.zip = zipProto; +import {zip} from '../../operator/zip'; +Observable.prototype.zip = zip; export var _void: void; \ No newline at end of file diff --git a/src/observable/ConnectableObservable.ts b/src/observable/ConnectableObservable.ts index 832b11d0b69..d587d2cfb96 100644 --- a/src/observable/ConnectableObservable.ts +++ b/src/observable/ConnectableObservable.ts @@ -13,7 +13,7 @@ export class ConnectableObservable extends Observable { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { return this._getSubject().subscribe(subscriber); } @@ -62,9 +62,9 @@ class RefCountObservable extends Observable { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { const connectable = this.connectable; - const refCountSubscriber = new RefCountSubscriber(subscriber, this); + const refCountSubscriber: RefCountSubscriber = new RefCountSubscriber(subscriber, this); const subscription = connectable.subscribe(refCountSubscriber); if (!subscription.isUnsubscribed && ++this.refCount === 1) { refCountSubscriber.connection = this.connection = connectable.connect(); diff --git a/src/observable/IteratorObservable.ts b/src/observable/IteratorObservable.ts index e35707c8829..548e2f7374f 100644 --- a/src/observable/IteratorObservable.ts +++ b/src/observable/IteratorObservable.ts @@ -5,18 +5,19 @@ import {root} from '../util/root'; import {SymbolShim} from '../util/SymbolShim'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; +import {Subscriber} from '../Subscriber'; export class IteratorObservable extends Observable { private iterator: any; static create(iterator: any, - project?: (x?: any, i?: number) => T, + project?: (value: any, index: number) => T, thisArg?: any, scheduler?: Scheduler) { return new IteratorObservable(iterator, project, thisArg, scheduler); } - static dispatch(state) { + static dispatch(state: any) { const { index, hasError, thisArg, project, iterator, subscriber } = state; @@ -54,7 +55,7 @@ export class IteratorObservable extends Observable { } constructor(iterator: any, - private project?: (x?: any, i?: number) => T, + private project?: (value: any, index: number) => T, private thisArg?: any, private scheduler?: Scheduler) { super(); @@ -67,7 +68,7 @@ export class IteratorObservable extends Observable { this.iterator = getIterator(iterator); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { let index = 0; const { iterator, project, thisArg, scheduler } = this; @@ -150,7 +151,7 @@ function getIterator(obj: any) { const maxSafeInteger = Math.pow(2, 53) - 1; -function toLength(o) { +function toLength(o: any) { let len = +o.length; if (isNaN(len)) { return 0; @@ -168,11 +169,11 @@ function toLength(o) { return len; } -function numberIsFinite(value) { +function numberIsFinite(value: any) { return typeof value === 'number' && root.isFinite(value); } -function sign(value) { +function sign(value: any) { let valueAsNumber = +value; if (valueAsNumber === 0) { return valueAsNumber; diff --git a/src/observable/ScalarObservable.ts b/src/observable/ScalarObservable.ts index c66b165750c..915748146e2 100644 --- a/src/observable/ScalarObservable.ts +++ b/src/observable/ScalarObservable.ts @@ -12,7 +12,7 @@ export class ScalarObservable extends Observable { return new ScalarObservable(value, scheduler); } - static dispatch(state): void { + static dispatch(state: any): void { const { done, value, subscriber } = state; if (done) { @@ -58,7 +58,7 @@ const proto = ScalarObservable.prototype; proto.map = function (project: (x: T, ix?: number) => R, thisArg?: any): Observable { let result = tryCatch(project).call(thisArg || this, this.value, 0); if (result === errorObject) { - return new ErrorObservable(errorObject.e); + return new ErrorObservable(errorObject.e); } else { return new ScalarObservable(project.call(thisArg || this, this.value, 0)); } @@ -67,11 +67,11 @@ proto.map = function (project: (x: T, ix?: number) => R, thisArg?: any): O proto.filter = function (select: (x: T, ix?: number) => boolean, thisArg?: any): Observable { let result = tryCatch(select).call(thisArg || this, this.value, 0); if (result === errorObject) { - return new ErrorObservable(errorObject.e); + return new ErrorObservable(errorObject.e); } else if (result) { return this; } else { - return new EmptyObservable(); + return new EmptyObservable(); } }; @@ -80,8 +80,8 @@ proto.reduce = function (project: (acc: R, x: T) => R, seed?: R): Observab return this; } let result = tryCatch(project)(seed, this.value); - if (result === errorObject) { - return new ErrorObservable(errorObject.e); + if (result as any === errorObject) { + return new ErrorObservable(errorObject.e); } else { return new ScalarObservable(result); } @@ -97,7 +97,7 @@ proto.count = function (predicate?: (value: T, index: number, source: Observa } else { let result = tryCatch(predicate).call(this, this.value, 0, this); if (result === errorObject) { - return new ErrorObservable(errorObject.e); + return new ErrorObservable(errorObject.e); } else { return new ScalarObservable(result ? 1 : 0); } @@ -106,7 +106,7 @@ proto.count = function (predicate?: (value: T, index: number, source: Observa proto.skip = function (count: number): Observable { if (count > 0) { - return new EmptyObservable(); + return new EmptyObservable(); } return this; }; @@ -115,5 +115,5 @@ proto.take = function (count: number): Observable { if (count > 0) { return this; } - return new EmptyObservable(); + return new EmptyObservable(); }; diff --git a/src/observable/bindCallback.ts b/src/observable/bindCallback.ts index 534d9fc73cf..53f163fee2f 100644 --- a/src/observable/bindCallback.ts +++ b/src/observable/bindCallback.ts @@ -10,15 +10,15 @@ export class BoundCallbackObservable extends Observable { subject: AsyncSubject; static create(callbackFunc: Function, - selector: Function = undefined, - scheduler?: Scheduler): Function { - return (...args): Observable => { - return new BoundCallbackObservable(callbackFunc, selector, args, scheduler); + selector: Function | void = undefined, + scheduler?: Scheduler): (...args: any[]) => Observable { + return (...args: any[]): Observable => { + return new BoundCallbackObservable(callbackFunc, selector, args, scheduler); }; } constructor(private callbackFunc: Function, - private selector, + private selector: Function, private args: any[], public scheduler: Scheduler) { super(); @@ -33,7 +33,7 @@ export class BoundCallbackObservable extends Observable { if (!scheduler) { if (!subject) { subject = this.subject = new AsyncSubject(); - const handler = function handlerFn(...innerArgs) { + const handler = function handlerFn(...innerArgs: any[]) { const source = (handlerFn).source; const { selector, subject } = source; if (selector) { @@ -73,7 +73,7 @@ function dispatch(state: { source: BoundCallbackObservable, subscriber: Su if (!subject) { subject = source.subject = new AsyncSubject(); - const handler = function handlerFn(...innerArgs) { + const handler = function handlerFn(...innerArgs: any[]) { const source = (handlerFn).source; const { selector, subject } = source; if (selector) { diff --git a/src/observable/defer.ts b/src/observable/defer.ts index 1d1aa3c3f00..157b03586ba 100644 --- a/src/observable/defer.ts +++ b/src/observable/defer.ts @@ -15,7 +15,7 @@ export class DeferObservable extends Observable { _subscribe(subscriber: Subscriber) { const result = tryCatch(this.observableFactory)(); - if (result === errorObject) { + if (result as any === errorObject) { subscriber.error(errorObject.e); } else { result.subscribe(subscriber); diff --git a/src/observable/empty.ts b/src/observable/empty.ts index c3f548b3f43..8e1bb5b751d 100644 --- a/src/observable/empty.ts +++ b/src/observable/empty.ts @@ -1,10 +1,11 @@ import {Scheduler} from '../Scheduler'; +import {Subscriber} from '../Subscriber'; import {Observable} from '../Observable'; export class EmptyObservable extends Observable { static create(scheduler?: Scheduler): Observable { - return new EmptyObservable(scheduler); + return new EmptyObservable(scheduler); } static dispatch({ subscriber }) { @@ -15,7 +16,7 @@ export class EmptyObservable extends Observable { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { const scheduler = this.scheduler; diff --git a/src/observable/forkJoin.ts b/src/observable/forkJoin.ts index 41da37536ec..efc6a88808d 100644 --- a/src/observable/forkJoin.ts +++ b/src/observable/forkJoin.ts @@ -7,16 +7,15 @@ import {isArray} from '../util/isArray'; export class ForkJoinObservable extends Observable { constructor(private sources: Array | Promise>, - private resultSelector?: (...values: Array) => any) { + private resultSelector?: (...values: Array) => T) { super(); } - static create(...sources: Array | + static create(...sources: Array | Promise | Array> | - Promise | - ((...values: Array) => any)>): Observable { + ((...values: Array) => any)>): Observable { if (sources === null || arguments.length === 0) { - return new EmptyObservable(); + return new EmptyObservable(); } let resultSelector: (...values: Array) => any = null; @@ -49,7 +48,7 @@ export class ForkJoinObservable extends Observable { } class AllSubscriber extends Subscriber { - private _value: any = null; + private _value: T = null; constructor(destination: Subscriber, private index: number, @@ -60,7 +59,7 @@ class AllSubscriber extends Subscriber { super(destination); } - _next(value: any): void { + _next(value: T): void { this._value = value; } @@ -95,7 +94,7 @@ function hasValue(x: any): boolean { } function emptyArray(len: number): any[] { - let arr = []; + let arr: any[] = []; for (let i = 0; i < len; i++) { arr.push(null); } diff --git a/src/observable/from.ts b/src/observable/from.ts index 3524e029d22..57839fdef6b 100644 --- a/src/observable/from.ts +++ b/src/observable/from.ts @@ -9,26 +9,27 @@ import {Subscriber} from '../Subscriber'; import {ObserveOnSubscriber} from '../operator/observeOn-support'; import {queue} from '../scheduler/queue'; -const isArray = Array.isArray; +import {isPromise} from '../util/isPromise'; +import {isArray} from '../util/isArray'; export class FromObservable extends Observable { - constructor(private ish: any, private scheduler: Scheduler) { + constructor(private ish: Observable | Promise | Iterator | ArrayLike, private scheduler: Scheduler) { super(null); } - static create(ish: any, scheduler: Scheduler = queue): Observable { + static create(ish: Observable | Promise | Iterator | ArrayLike, scheduler: Scheduler = queue): Observable { if (ish) { if (isArray(ish)) { return new ArrayObservable(ish, scheduler); - } else if (typeof ish.then === 'function') { + } else if (isPromise(ish)) { return new PromiseObservable(ish, scheduler); } else if (typeof ish[SymbolShim.observable] === 'function') { if (ish instanceof Observable) { return ish; } - return new FromObservable(ish, scheduler); + return new FromObservable(ish, scheduler); } else if (typeof ish[SymbolShim.iterator] === 'function') { - return new IteratorObservable(ish, null, null, scheduler); + return new IteratorObservable(ish, null, null, scheduler); } } diff --git a/src/observable/fromArray.ts b/src/observable/fromArray.ts index ddeafec1986..10d71a29c72 100644 --- a/src/observable/fromArray.ts +++ b/src/observable/fromArray.ts @@ -2,6 +2,7 @@ import {Scheduler} from '../Scheduler'; import {Observable} from '../Observable'; import {ScalarObservable} from './ScalarObservable'; import {EmptyObservable} from './empty'; +import {Subscriber} from '../Subscriber'; import {isScheduler} from '../util/isScheduler'; export class ArrayObservable extends Observable { @@ -20,15 +21,15 @@ export class ArrayObservable extends Observable { const len = array.length; if (len > 1) { - return new ArrayObservable(array, scheduler); + return new ArrayObservable(array, scheduler); } else if (len === 1) { - return new ScalarObservable(array[0], scheduler); + return new ScalarObservable(array[0], scheduler); } else { - return new EmptyObservable(scheduler); + return new EmptyObservable(scheduler); } } - static dispatch(state) { + static dispatch(state: any) { const { array, index, count, subscriber } = state; @@ -59,7 +60,7 @@ export class ArrayObservable extends Observable { } } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { let index = 0; const array = this.array; diff --git a/src/observable/fromEvent.ts b/src/observable/fromEvent.ts index ccc2571279d..38ab86d4ac8 100644 --- a/src/observable/fromEvent.ts +++ b/src/observable/fromEvent.ts @@ -15,7 +15,7 @@ export class FromEventObservable extends Observable { } private static setupSubscription(sourceObj: any, eventName: string, handler: Function, subscriber: Subscriber) { - let unsubscribe; + let unsubscribe: () => void; let tag = sourceObj.toString(); if (tag === '[object NodeList]' || tag === '[object HTMLCollection]') { for (let i = 0, len = sourceObj.length; i < len; i++) { @@ -35,18 +35,18 @@ export class FromEventObservable extends Observable { subscriber.add(new Subscription(unsubscribe)); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { const sourceObj = this.sourceObj; const eventName = this.eventName; const selector = this.selector; - let handler = selector ? (e) => { + let handler = selector ? (e: any) => { let result = tryCatch(selector)(e); - if (result === errorObject) { - subscriber.error(result.e); + if (result as any === errorObject) { + subscriber.error(errorObject.e); } else { subscriber.next(result); } - } : (e) => subscriber.next(e); + } : (e: any) => subscriber.next(e); FromEventObservable.setupSubscription(sourceObj, eventName, handler, subscriber); } diff --git a/src/observable/fromEventPattern.ts b/src/observable/fromEventPattern.ts index e806eb00bbf..967ee44f03f 100644 --- a/src/observable/fromEventPattern.ts +++ b/src/observable/fromEventPattern.ts @@ -2,6 +2,7 @@ import {Observable} from '../Observable'; import {Subscription} from '../Subscription'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; +import {Subscriber} from '../Subscriber'; export class FromEventPatternObservable extends Observable { @@ -17,19 +18,19 @@ export class FromEventPatternObservable extends Observable { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { const addHandler = this.addHandler; const removeHandler = this.removeHandler; const selector = this.selector; - const handler = selector ? function(e) { + const handler = selector ? function(e: any) { let result = tryCatch(selector).apply(null, arguments); if (result === errorObject) { subscriber.error(result.e); } else { subscriber.next(result); } - } : function(e) { subscriber.next(e); }; + } : function(e: any) { subscriber.next(e); }; let result = tryCatch(addHandler)(handler); if (result === errorObject) { diff --git a/src/observable/interval.ts b/src/observable/interval.ts index 33c6b22b4ec..96511a27743 100644 --- a/src/observable/interval.ts +++ b/src/observable/interval.ts @@ -4,12 +4,12 @@ import {Scheduler} from '../Scheduler'; import {Observable} from '../Observable'; import {asap} from '../scheduler/asap'; -export class IntervalObservable extends Observable { +export class IntervalObservable extends Observable { static create(period: number = 0, scheduler: Scheduler = asap): Observable { return new IntervalObservable(period, scheduler); } - static dispatch(state): void { + static dispatch(state: any): void { const { index, subscriber, period } = state; subscriber.next(index); @@ -33,7 +33,7 @@ export class IntervalObservable extends Observable { } } - _subscribe(subscriber: Subscriber) { + _subscribe(subscriber: Subscriber) { const index = 0; const period = this.period; const scheduler = this.scheduler; diff --git a/src/observable/never.ts b/src/observable/never.ts index 8007242ed17..530d882d1c9 100644 --- a/src/observable/never.ts +++ b/src/observable/never.ts @@ -4,7 +4,7 @@ import {noop} from '../util/noop'; export class InfiniteObservable extends Observable { static create() { - return new InfiniteObservable(); + return new InfiniteObservable(); } constructor() { diff --git a/src/observable/range.ts b/src/observable/range.ts index bf305b20abb..0c239237d79 100644 --- a/src/observable/range.ts +++ b/src/observable/range.ts @@ -1,13 +1,14 @@ import {Scheduler} from '../Scheduler'; import {Observable} from '../Observable'; +import {Subscriber} from '../Subscriber'; -export class RangeObservable extends Observable { +export class RangeObservable extends Observable { static create(start: number = 0, end: number = 0, scheduler?: Scheduler): Observable { return new RangeObservable(start, end, scheduler); } - static dispatch(state) { + static dispatch(state: any) { const { start, index, end, subscriber } = state; @@ -39,7 +40,7 @@ export class RangeObservable extends Observable { this.scheduler = scheduler; } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { let index = 0; let start = this.start; diff --git a/src/observable/throw.ts b/src/observable/throw.ts index a29096c0b40..c7d77a0c562 100644 --- a/src/observable/throw.ts +++ b/src/observable/throw.ts @@ -4,7 +4,7 @@ import {Observable} from '../Observable'; export class ErrorObservable extends Observable { static create(error: T, scheduler?: Scheduler) { - return new ErrorObservable(error, scheduler); + return new ErrorObservable(error, scheduler); } static dispatch({ error, subscriber }) { @@ -15,7 +15,7 @@ export class ErrorObservable extends Observable { super(); } - _subscribe(subscriber) { + _subscribe(subscriber: any) { const error = this.error; const scheduler = this.scheduler; diff --git a/src/observable/timer.ts b/src/observable/timer.ts index 1fe68abcbdd..47baaa1d0de 100644 --- a/src/observable/timer.ts +++ b/src/observable/timer.ts @@ -4,14 +4,15 @@ import {Observable} from '../Observable'; import {asap} from '../scheduler/asap'; import {isScheduler} from '../util/isScheduler'; import {isDate} from '../util/isDate'; +import {Subscriber} from '../Subscriber'; -export class TimerObservable extends Observable { +export class TimerObservable extends Observable { static create(dueTime: number | Date = 0, period?: number | Scheduler, scheduler?: Scheduler): Observable { return new TimerObservable(dueTime, period, scheduler); } - static dispatch(state) { + static dispatch(state: any) { const { index, period, subscriber } = state; const action = ( this); @@ -57,7 +58,7 @@ export class TimerObservable extends Observable { this.dueTime = absoluteDueTime ? (+dueTime - this.scheduler.now()) : dueTime; } - _subscribe(subscriber) { + _subscribe(subscriber: Subscriber) { const index = 0; const period = this._period; diff --git a/src/operator/buffer.ts b/src/operator/buffer.ts index 79e9df9a7b6..5ee91c1857c 100644 --- a/src/operator/buffer.ts +++ b/src/operator/buffer.ts @@ -11,24 +11,24 @@ import {Observable} from '../Observable'; * @returns {Observable} an observable of buffers, which are arrays of values */ export function buffer(closingNotifier: Observable): Observable { - return this.lift(new BufferOperator(closingNotifier)); + return this.lift(new BufferOperator(closingNotifier)); } -class BufferOperator implements Operator { +class BufferOperator implements Operator { constructor(private closingNotifier: Observable) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber): Subscriber { return new BufferSubscriber(subscriber, this.closingNotifier); } } class BufferSubscriber extends Subscriber { private buffer: T[] = []; - private notifierSubscriber: BufferClosingNotifierSubscriber = null; + private notifierSubscriber: BufferClosingNotifierSubscriber = null; - constructor(destination: Subscriber, closingNotifier: Observable) { + constructor(destination: Subscriber, closingNotifier: Observable) { super(destination); this.notifierSubscriber = new BufferClosingNotifierSubscriber(this); this.add(closingNotifier._subscribe(this.notifierSubscriber)); @@ -57,12 +57,12 @@ class BufferSubscriber extends Subscriber { } } -class BufferClosingNotifierSubscriber extends Subscriber { +class BufferClosingNotifierSubscriber extends Subscriber { constructor(private parent: BufferSubscriber) { super(null); } - _next(value: T) { + _next(value: any) { this.parent.flushBuffer(); } diff --git a/src/operator/bufferCount.ts b/src/operator/bufferCount.ts index b2ec1c50da4..52edbfeda92 100644 --- a/src/operator/bufferCount.ts +++ b/src/operator/bufferCount.ts @@ -15,11 +15,11 @@ export function bufferCount(bufferSize: number, startBufferEvery: number = nu return this.lift(new BufferCountOperator(bufferSize, startBufferEvery)); } -class BufferCountOperator implements Operator { +class BufferCountOperator implements Operator { constructor(private bufferSize: number, private startBufferEvery: number) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber): Subscriber { return new BufferCountSubscriber(subscriber, this.bufferSize, this.startBufferEvery); } } @@ -28,7 +28,7 @@ class BufferCountSubscriber extends Subscriber { private buffers: Array = [[]]; private count: number = 0; - constructor(destination: Subscriber, private bufferSize: number, private startBufferEvery: number) { + constructor(destination: Subscriber, private bufferSize: number, private startBufferEvery: number) { super(destination); } diff --git a/src/operator/bufferTime.ts b/src/operator/bufferTime.ts index 13a17332f10..90b4b753ab2 100644 --- a/src/operator/bufferTime.ts +++ b/src/operator/bufferTime.ts @@ -19,13 +19,13 @@ export function bufferTime(bufferTimeSpan: number, return this.lift(new BufferTimeOperator(bufferTimeSpan, bufferCreationInterval, scheduler)); } -class BufferTimeOperator implements Operator { +class BufferTimeOperator implements Operator { constructor(private bufferTimeSpan: number, private bufferCreationInterval: number, private scheduler: Scheduler) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber): Subscriber { return new BufferTimeSubscriber( subscriber, this.bufferTimeSpan, this.bufferCreationInterval, this.scheduler ); @@ -35,7 +35,7 @@ class BufferTimeOperator implements Operator { class BufferTimeSubscriber extends Subscriber { private buffers: Array = []; - constructor(destination: Subscriber, + constructor(destination: Subscriber, private bufferTimeSpan: number, private bufferCreationInterval: number, private scheduler: Scheduler) { @@ -60,7 +60,7 @@ class BufferTimeSubscriber extends Subscriber { } } - _error(err) { + _error(err: any) { this.buffers.length = 0; this.destination.error(err); } @@ -74,7 +74,7 @@ class BufferTimeSubscriber extends Subscriber { } openBuffer(): T[] { - let buffer = []; + let buffer: T[] = []; this.buffers.push(buffer); return buffer; } @@ -86,7 +86,7 @@ class BufferTimeSubscriber extends Subscriber { } } -function dispatchBufferTimeSpanOnly(state) { +function dispatchBufferTimeSpanOnly(state: any) { const subscriber: BufferTimeSubscriber = state.subscriber; const prevBuffer = state.buffer; @@ -100,7 +100,7 @@ function dispatchBufferTimeSpanOnly(state) { } } -function dispatchBufferCreation(state) { +function dispatchBufferCreation(state: any) { const { bufferCreationInterval, bufferTimeSpan, subscriber, scheduler } = state; const buffer = subscriber.openBuffer(); const action = this; diff --git a/src/operator/bufferToggle.ts b/src/operator/bufferToggle.ts index dfa6111bfcb..7feeb576a76 100644 --- a/src/operator/bufferToggle.ts +++ b/src/operator/bufferToggle.ts @@ -14,18 +14,18 @@ import {errorObject} from '../util/errorObject'; * @returns {Observable} an observable of arrays of buffered values. */ export function bufferToggle(openings: Observable, - closingSelector: (openValue: O) => Observable): Observable { - return this.lift(new BufferToggleOperator(openings, closingSelector)); + closingSelector: (value: O) => Observable): Observable { + return this.lift(new BufferToggleOperator(openings, closingSelector)); } -class BufferToggleOperator implements Operator { +class BufferToggleOperator implements Operator { constructor(private openings: Observable, - private closingSelector: (openValue: O) => Observable) { + private closingSelector: (value: O) => Observable) { } - call(subscriber: Subscriber): Subscriber { - return new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector); + call(subscriber: Subscriber): Subscriber { + return new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector); } } @@ -37,9 +37,9 @@ interface BufferContext { class BufferToggleSubscriber extends Subscriber { private contexts: Array> = []; - constructor(destination: Subscriber, + constructor(destination: Subscriber, private openings: Observable, - private closingSelector: (openValue: O) => Observable) { + private closingSelector: (value: O) => Observable) { super(destination); this.add(this.openings._subscribe(new BufferToggleOpeningsSubscriber(this))); } @@ -82,15 +82,15 @@ class BufferToggleSubscriber extends Subscriber { const contexts = this.contexts; let closingNotifier = tryCatch(closingSelector)(value); - if (closingNotifier === errorObject) { - this._error(closingNotifier.e); + if (closingNotifier as any === errorObject) { + this._error(errorObject.e); } else { let context = { - buffer: [], - subscription: new Subscription() + buffer: [], + subscription: new Subscription() }; contexts.push(context); - const subscriber = new BufferToggleClosingsSubscriber(this, context); + const subscriber = new BufferToggleClosingsSubscriber(this, context); const subscription = closingNotifier._subscribe(subscriber); context.subscription.add(subscription); this.add(subscription); @@ -110,16 +110,16 @@ class BufferToggleSubscriber extends Subscriber { } } -class BufferToggleOpeningsSubscriber extends Subscriber { - constructor(private parent: BufferToggleSubscriber) { +class BufferToggleOpeningsSubscriber extends Subscriber { + constructor(private parent: BufferToggleSubscriber) { super(null); } - _next(value: T) { + _next(value: O) { this.parent.openBuffer(value); } - _error(err) { + _error(err: any) { this.parent.error(err); } @@ -128,8 +128,8 @@ class BufferToggleOpeningsSubscriber extends Subscriber { } } -class BufferToggleClosingsSubscriber extends Subscriber { - constructor(private parent: BufferToggleSubscriber, +class BufferToggleClosingsSubscriber extends Subscriber { + constructor(private parent: BufferToggleSubscriber, private context: { subscription: any, buffer: T[] }) { super(null); } @@ -138,7 +138,7 @@ class BufferToggleClosingsSubscriber extends Subscriber { this.parent.closeBuffer(this.context); } - _error(err) { + _error(err: any) { this.parent.error(err); } diff --git a/src/operator/bufferWhen.ts b/src/operator/bufferWhen.ts index 699ce196754..20b37a5dd43 100644 --- a/src/operator/bufferWhen.ts +++ b/src/operator/bufferWhen.ts @@ -15,12 +15,12 @@ export function bufferWhen(closingSelector: () => Observable): Observabl return this.lift(new BufferWhenOperator(closingSelector)); } -class BufferWhenOperator implements Operator { +class BufferWhenOperator implements Operator { constructor(private closingSelector: () => Observable) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber): Subscriber { return new BufferWhenSubscriber(subscriber, this.closingSelector); } } @@ -29,7 +29,7 @@ class BufferWhenSubscriber extends Subscriber { private buffer: T[]; private closingNotification: Subscription; - constructor(destination: Subscriber, private closingSelector: () => Observable) { + constructor(destination: Subscriber, private closingSelector: () => Observable) { super(destination); this.openBuffer(); } @@ -64,8 +64,8 @@ class BufferWhenSubscriber extends Subscriber { this.buffer = []; let closingNotifier = tryCatch(this.closingSelector)(); - if (closingNotifier === errorObject) { - const err = closingNotifier.e; + if (closingNotifier as any === errorObject) { + const err = errorObject.e; this.buffer = null; this.destination.error(err); } else { @@ -74,7 +74,7 @@ class BufferWhenSubscriber extends Subscriber { } } -class BufferClosingNotifierSubscriber extends Subscriber { +class BufferClosingNotifierSubscriber extends Subscriber { constructor(private parent: BufferWhenSubscriber) { super(null); } @@ -83,7 +83,7 @@ class BufferClosingNotifierSubscriber extends Subscriber { this.parent.openBuffer(); } - _error(err) { + _error(err: any) { this.parent.error(err); } diff --git a/src/operator/catch.ts b/src/operator/catch.ts index 450d40b0da2..76feb077557 100644 --- a/src/operator/catch.ts +++ b/src/operator/catch.ts @@ -13,7 +13,7 @@ import {errorObject} from '../util/errorObject'; * @return {Observable} an observable that originates from either the source or the observable returned by the * catch `selector` function. */ -export function _catch(selector: (err: any, caught: Observable) => Observable): Observable { +export function _catch(selector: (err: any, caught: Observable) => Observable): Observable { let catchOperator = new CatchOperator(selector); let caught = this.lift(catchOperator); catchOperator.caught = caught; @@ -46,9 +46,9 @@ class CatchSubscriber extends Subscriber { this.destination.next(value); } - _error(err) { + _error(err: any) { const result = tryCatch(this.selector)(err, this.caught); - if (result === errorObject) { + if (result as any === errorObject) { this.destination.error(errorObject.e); } else { this.lastSubscription.unsubscribe(); diff --git a/src/operator/combineAll.ts b/src/operator/combineAll.ts index 3fc3cc30ff3..cde0e3794ea 100644 --- a/src/operator/combineAll.ts +++ b/src/operator/combineAll.ts @@ -1,4 +1,5 @@ import {CombineLatestOperator} from './combineLatest-support'; +import {Observable} from '../Observable'; /** * Takes an Observable of Observables, and collects all observables from it. Once the outer observable @@ -12,6 +13,6 @@ import {CombineLatestOperator} from './combineLatest-support'; * most recent values from each collected observable as arguments, in order. * @returns {Observable} an observable of projected results or arrays of recent values. */ -export function combineAll(project?: (...values: Array) => R) { +export function combineAll(project?: (...values: Array) => R): Observable { return this.lift(new CombineLatestOperator(project)); } diff --git a/src/operator/combineLatest-static.ts b/src/operator/combineLatest-static.ts index 80c95403722..80242498e8f 100644 --- a/src/operator/combineLatest-static.ts +++ b/src/operator/combineLatest-static.ts @@ -15,10 +15,10 @@ import {isArray} from '../util/isArray'; * @returns {Observable} an observable of other projected values from the most recent values from each observable, or an array of each of * the most recent values from each observable. */ -export function combineLatest(...observables: Array | - Array> | - ((...values: Array) => R) | - Scheduler>): Observable { +export function combineLatest(...observables: Array | + Array> | + (((...values: Array) => R)) | + Scheduler>): Observable { let project: (...values: Array) => R = null; let scheduler: Scheduler = null; @@ -36,5 +36,5 @@ export function combineLatest(...observables: Array | observables = >>observables[0]; } - return new ArrayObservable(observables, scheduler).lift(new CombineLatestOperator(project)); + return new ArrayObservable(observables, scheduler).lift(new CombineLatestOperator(project)); } diff --git a/src/operator/combineLatest-support.ts b/src/operator/combineLatest-support.ts index fc441cddad6..b9f87cea30f 100644 --- a/src/operator/combineLatest-support.ts +++ b/src/operator/combineLatest-support.ts @@ -11,7 +11,7 @@ export class CombineLatestOperator implements Operator { } call(subscriber: Subscriber): Subscriber { - return new CombineLatestSubscriber(subscriber, this.project); + return new CombineLatestSubscriber(subscriber, this.project); } } diff --git a/src/operator/combineLatest.ts b/src/operator/combineLatest.ts index 08b77ff125f..96d457c91f4 100644 --- a/src/operator/combineLatest.ts +++ b/src/operator/combineLatest.ts @@ -13,10 +13,10 @@ import {isArray} from '../util/isArray'; * @returns {Observable} an observable of other projected values from the most recent values from each observable, or an array of each of * the most recent values from each observable. */ -export function combineLatest(...observables: Array | +export function combineLatest(...observables: Array | Array> | ((...values: Array) => R)>): Observable { - let project: (...values: Array) => R = null; + let project: (...values: Array) => R = null; if (typeof observables[observables.length - 1] === 'function') { project = <(...values: Array) => R>observables.pop(); } @@ -24,10 +24,10 @@ export function combineLatest(...observables: Array | // if the first and only other argument besides the resultSelector is an array // assume it's been called with `combineLatest([obs1, obs2, obs3], project)` if (observables.length === 1 && isArray(observables[0])) { - observables = >>observables[0]; + observables = observables[0]; } observables.unshift(this); - return new ArrayObservable(observables).lift(new CombineLatestOperator(project)); + return new ArrayObservable(observables).lift(new CombineLatestOperator(project)); } diff --git a/src/operator/concat-static.ts b/src/operator/concat-static.ts index 4c3f55ab7c5..4432cfd64ef 100644 --- a/src/operator/concat-static.ts +++ b/src/operator/concat-static.ts @@ -12,12 +12,12 @@ import {isScheduler} from '../util/isScheduler'; * @params {Scheduler} [scheduler] an optional scheduler to schedule each observable subscription on. * @returns {Observable} All values of each passed observable merged into a single observable, in order, in serial fashion. */ -export function concat(...observables: Array | Scheduler>): Observable { +export function concat(...observables: Array | Scheduler>): Observable { let scheduler: Scheduler = queue; let args = observables; if (isScheduler(args[observables.length - 1])) { scheduler = args.pop(); } - return new ArrayObservable(observables, scheduler).lift(new MergeAllOperator(1)); + return new ArrayObservable(observables, scheduler).lift, T>(new MergeAllOperator(1)); } diff --git a/src/operator/concat.ts b/src/operator/concat.ts index 2e07fd43e43..b144b8e29d3 100644 --- a/src/operator/concat.ts +++ b/src/operator/concat.ts @@ -10,9 +10,9 @@ import {MergeAllOperator} from './mergeAll-support'; * on to the next. * @params {...Observable} the observables to concatenate * @params {Scheduler} [scheduler] an optional scheduler to schedule each observable subscription on. - * @returns {Observable} All values of each passed observable merged into a single observable, in order, in serial fashion. +* @returns {Observable} All values of each passed observable merged into a single observable, in order, in serial fashion. */ -export function concat(...observables: (Observable | Scheduler)[]): Observable { +export function concat(...observables: Array | Scheduler>): Observable { let args = observables; args.unshift(this); @@ -21,5 +21,5 @@ export function concat(...observables: (Observable | Scheduler)[]): Obse scheduler = args.pop(); } - return new ArrayObservable(args, scheduler).lift(new MergeAllOperator(1)); + return new ArrayObservable(args, scheduler).lift, R>(new MergeAllOperator(1)); } diff --git a/src/operator/concatAll.ts b/src/operator/concatAll.ts index 7cb11cd28f6..4ab26ec6950 100644 --- a/src/operator/concatAll.ts +++ b/src/operator/concatAll.ts @@ -1,4 +1,3 @@ -import {Observable} from '../Observable'; import {MergeAllOperator} from './mergeAll-support'; /** @@ -12,6 +11,6 @@ import {MergeAllOperator} from './mergeAll-support'; * * @returns {Observable} an observable of values merged from the incoming observables. */ -export function concatAll(): Observable { +export function concatAll(): T { return this.lift(new MergeAllOperator(1)); } diff --git a/src/operator/concatMap.ts b/src/operator/concatMap.ts index eb2488a903e..46d396ffe5e 100644 --- a/src/operator/concatMap.ts +++ b/src/operator/concatMap.ts @@ -1,5 +1,5 @@ -import {Observable} from '../Observable'; import {MergeMapOperator} from './mergeMap-support'; +import {Observable} from '../Observable'; /** * Maps values from the source observable into new Observables, then merges them in a serialized fashion, @@ -11,7 +11,7 @@ import {MergeMapOperator} from './mergeMap-support'; * * @param {function} project a function to map incoming values into Observables to be concatenated. accepts * the `value` and the `index` as arguments. - * @param {function} [projectResult] an optional result selector that is applied to values before they're + * @param {function} [resultSelector] an optional result selector that is applied to values before they're * merged into the returned observable. The arguments passed to this function are: * - `outerValue`: the value that came from the source * - `innerValue`: the value that came from the projected Observable @@ -20,7 +20,7 @@ import {MergeMapOperator} from './mergeMap-support'; * @returns {Observable} an observable of values merged from the projected Observables as they were subscribed to, * one at a time. Optionally, these values may have been projected from a passed `projectResult` argument. */ -export function concatMap(project: (value: T, index: number) => Observable, - projectResult?: (outerValue: T, innerValue: any, outerIndex: number, innerIndex: number) => R) { - return this.lift(new MergeMapOperator(project, projectResult, 1)); +export function concatMap(project: (value: T, index: number) => Observable | Promise, + resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { + return this.lift(new MergeMapOperator(project, resultSelector, 1)); } diff --git a/src/operator/concatMapTo.ts b/src/operator/concatMapTo.ts index 434817f7f5f..bd17d5df1cd 100644 --- a/src/operator/concatMapTo.ts +++ b/src/operator/concatMapTo.ts @@ -5,7 +5,7 @@ import {MergeMapToOperator} from './mergeMapTo-support'; * Maps values from the source to a specific observable, and merges them together in a serialized fashion. * * @param {Observable} observable the observable to map each source value to - * @param {function} [projectResult] an optional result selector that is applied to values before they're + * @param {function} [resultSelector] an optional result selector that is applied to values before they're * merged into the returned observable. The arguments passed to this function are: * - `outerValue`: the value that came from the source * - `innerValue`: the value that came from the projected Observable @@ -14,10 +14,11 @@ import {MergeMapToOperator} from './mergeMapTo-support'; * @returns {Observable} an observable of values merged together by joining the passed observable * with itself, one after the other, for each value emitted from the source. */ -export function concatMapTo(observable: Observable, - projectResult?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2): Observable { - return this.lift(new MergeMapToOperator(observable, projectResult, 1)); +export function concatMapTo(observable: Observable, + resultSelector?: ( + outerValue: T, + innerValue: R, + outerIndex: number, + innerIndex: number) => TResult): Observable { + return this.lift(new MergeMapToOperator(observable, resultSelector, 1)); } diff --git a/src/operator/count.ts b/src/operator/count.ts index 561bf65124f..b70e44b1436 100644 --- a/src/operator/count.ts +++ b/src/operator/count.ts @@ -19,28 +19,26 @@ import {errorObject} from '../util/errorObject'; * @returns {Observable} an observable of one number that represents the count as described * above */ -export function count(predicate?: (value: T, - index: number, - source: Observable) => boolean): Observable { +export function count(predicate?: (value: T, index: number, observable: Observable) => boolean): Observable { return this.lift(new CountOperator(predicate, this)); } -class CountOperator implements Operator { - constructor(private predicate?: (value: T, index: number, source: Observable) => boolean, +class CountOperator implements Operator { + constructor(private predicate?: (value: T, index: number, observable: Observable) => boolean, private source?: Observable) { } - call(subscriber: Subscriber): Subscriber { - return new CountSubscriber(subscriber, this.predicate, this.source); + call(subscriber: Subscriber): Subscriber { + return new CountSubscriber(subscriber, this.predicate, this.source); } } -class CountSubscriber extends Subscriber { +class CountSubscriber extends Subscriber { private count: number = 0; private index: number = 0; - constructor(destination: Observer, - private predicate?: (value: T, index: number, source: Observable) => boolean, + constructor(destination: Observer, + private predicate?: (value: T, index: number, observable: Observable) => boolean, private source?: Observable) { super(destination); } diff --git a/src/operator/debounce.ts b/src/operator/debounce.ts index d6ab707400c..f5d47f930a3 100644 --- a/src/operator/debounce.ts +++ b/src/operator/debounce.ts @@ -8,12 +8,12 @@ import {tryCatch} from '../util/tryCatch'; import {isPromise} from '../util/isPromise'; import {errorObject} from '../util/errorObject'; -export function debounce(durationSelector: (value: T) => Observable | Promise): Observable { +export function debounce(durationSelector: (value: T) => Observable | Promise): Observable { return this.lift(new DebounceOperator(durationSelector)); } -class DebounceOperator implements Operator { - constructor(private durationSelector: (value: T) => Observable | Promise) { +class DebounceOperator implements Operator { + constructor(private durationSelector: (value: T) => Observable | Promise) { } call(observer: Subscriber): Subscriber { @@ -30,7 +30,7 @@ class DebounceSubscriber extends Subscriber { } constructor(destination: Subscriber, - private durationSelector: (value: T) => Observable | Promise) { + private durationSelector: (value: T) => Observable | Promise) { super(destination); } @@ -39,16 +39,16 @@ class DebounceSubscriber extends Subscriber { const currentIndex = ++this._index; let debounce = tryCatch(this.durationSelector)(value); - if (debounce === errorObject) { + if (debounce as any === errorObject) { destination.error(errorObject.e); } else { if (isPromise(debounce)) { - debounce = PromiseObservable.create(debounce); + debounce = PromiseObservable.create(debounce as Promise); } this.lastValue = value; this.clearDebounce(); - this.add(this.debouncedSubscription = debounce._subscribe(new DurationSelectorSubscriber(this, currentIndex))); + this.add(this.debouncedSubscription = (debounce as Observable)._subscribe(new DurationSelectorSubscriber(this, currentIndex))); } } @@ -76,8 +76,8 @@ class DebounceSubscriber extends Subscriber { } } -class DurationSelectorSubscriber extends Subscriber { - constructor(private parent: DebounceSubscriber, +class DurationSelectorSubscriber extends Subscriber { + constructor(private parent: DebounceSubscriber, private currentIndex: number) { super(null); } @@ -93,11 +93,11 @@ class DurationSelectorSubscriber extends Subscriber { } } - _next(unused: T) { + _next(unused: number) { this.debounceNext(); } - _error(err) { + _error(err: any) { this.parent.error(err); } diff --git a/src/operator/debounceTime.ts b/src/operator/debounceTime.ts index 529617b758a..465ef79d968 100644 --- a/src/operator/debounceTime.ts +++ b/src/operator/debounceTime.ts @@ -9,7 +9,7 @@ export function debounceTime(dueTime: number, scheduler: Scheduler = asap): O return this.lift(new DebounceTimeOperator(dueTime, scheduler)); } -class DebounceTimeOperator implements Operator { +class DebounceTimeOperator implements Operator { constructor(private dueTime: number, private scheduler: Scheduler) { } @@ -58,6 +58,6 @@ class DebounceTimeSubscriber extends Subscriber { } } -function dispatchNext(subscriber) { +function dispatchNext(subscriber: DebounceTimeSubscriber) { subscriber.debouncedNext(); } diff --git a/src/operator/defaultIfEmpty.ts b/src/operator/defaultIfEmpty.ts index 087c653d67e..2afc59f315f 100644 --- a/src/operator/defaultIfEmpty.ts +++ b/src/operator/defaultIfEmpty.ts @@ -2,7 +2,7 @@ import {Operator} from '../Operator'; import {Observable} from '../Observable'; import {Subscriber} from '../Subscriber'; -export function defaultIfEmpty(defaultValue: R = null): Observable | Observable { +export function defaultIfEmpty(defaultValue: R = null): Observable { return this.lift(new DefaultIfEmptyOperator(defaultValue)); } diff --git a/src/operator/delay.ts b/src/operator/delay.ts index 03d98273916..13644f5f0e4 100644 --- a/src/operator/delay.ts +++ b/src/operator/delay.ts @@ -4,15 +4,16 @@ import {Subscriber} from '../Subscriber'; import {Notification} from '../Notification'; import {queue} from '../scheduler/queue'; import {isDate} from '../util/isDate'; +import {Observable} from '../Observable'; export function delay(delay: number|Date, - scheduler: Scheduler = queue) { + scheduler: Scheduler = queue): Observable { const absoluteDelay = isDate(delay); const delayFor = absoluteDelay ? (+delay - scheduler.now()) : delay; return this.lift(new DelayOperator(delayFor, scheduler)); } -class DelayOperator implements Operator { +class DelayOperator implements Operator { constructor(private delay: number, private scheduler: Scheduler) { } @@ -27,7 +28,7 @@ class DelaySubscriber extends Subscriber { private active: boolean = false; private errored: boolean = false; - private static dispatch(state): void { + private static dispatch(state: any): void { const source = state.source; const queue = source.queue; const scheduler = state.scheduler; @@ -64,7 +65,7 @@ class DelaySubscriber extends Subscriber { } const scheduler = this.scheduler; - const message = new DelayMessage(scheduler.now() + this.delay, notification); + const message = new DelayMessage(scheduler.now() + this.delay, notification); this.queue.push(message); if (this.active === false) { @@ -76,7 +77,7 @@ class DelaySubscriber extends Subscriber { this.scheduleNotification(Notification.createNext(value)); } - _error(err) { + _error(err: any) { this.errored = true; this.queue = []; this.destination.error(err); diff --git a/src/operator/distinctUntilChanged.ts b/src/operator/distinctUntilChanged.ts index 67d672030b7..aca73bd6278 100644 --- a/src/operator/distinctUntilChanged.ts +++ b/src/operator/distinctUntilChanged.ts @@ -2,13 +2,14 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; +import {Observable} from '../Observable'; -export function distinctUntilChanged(compare?: (x: T, y: T) => boolean) { +export function distinctUntilChanged(compare?: (value1: T, value2: T) => boolean): Observable { return this.lift(new DistinctUntilChangedOperator(compare)); } -class DistinctUntilChangedOperator implements Operator { - constructor(private compare: (x: T, y: T) => boolean) { +class DistinctUntilChangedOperator implements Operator { + constructor(private compare: (value1: T, value2: T) => boolean) { } call(subscriber: Subscriber): Subscriber { @@ -20,7 +21,7 @@ class DistinctUntilChangedSubscriber extends Subscriber { private value: T; private hasValue: boolean = false; - constructor(destination: Subscriber, compare: (x: T, y: T) => boolean) { + constructor(destination: Subscriber, compare: (value1: T, value2: T) => boolean) { super(destination); if (typeof compare === 'function') { this.compare = compare; diff --git a/src/operator/distinctUntilKeyChanged.ts b/src/operator/distinctUntilKeyChanged.ts index c6956cc8de1..046472630df 100644 --- a/src/operator/distinctUntilKeyChanged.ts +++ b/src/operator/distinctUntilKeyChanged.ts @@ -1,10 +1,11 @@ import {distinctUntilChanged} from './distinctUntilChanged'; +import {Observable} from '../Observable'; -export function distinctUntilKeyChanged(key: string, compare?: (x: any, y: any) => boolean) { - return distinctUntilChanged.call(this, function(x, y) { +export function distinctUntilKeyChanged(key: string, compare?: (value1: T, value2: T) => boolean): Observable { + return distinctUntilChanged.call(this, function(x: T, y: T) { if (compare) { return compare(x[key], y[key]); } return x[key] === y[key]; }); -} \ No newline at end of file +} diff --git a/src/operator/do.ts b/src/operator/do.ts index cce2b9a4b49..5dfe331cd5d 100644 --- a/src/operator/do.ts +++ b/src/operator/do.ts @@ -5,9 +5,10 @@ import {Subscriber} from '../Subscriber'; import {noop} from '../util/noop'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; +import {Observable} from '../Observable'; -export function _do(nextOrObserver?: Observer|((x: T) => void), error?: (e: any) => void, complete?: () => void) { - let next; +export function _do(nextOrObserver?: Observer | ((x: T) => void), error?: (e: any) => void, complete?: () => void): Observable { + let next: (x: T) => void; if (nextOrObserver && typeof nextOrObserver === 'object') { next = (>nextOrObserver).next; error = (>nextOrObserver).error; @@ -18,7 +19,7 @@ export function _do(nextOrObserver?: Observer|((x: T) => void), error?: (e return this.lift(new DoOperator(next || noop, error || noop, complete || noop)); } -class DoOperator implements Operator { +class DoOperator implements Operator { next: (x: T) => void; error: (e: any) => void; @@ -48,18 +49,18 @@ class DoSubscriber extends Subscriber { this.__complete = complete; } - _next(x) { + _next(x: T) { const result = tryCatch(this.__next)(x); - if (result === errorObject) { + if (result as any === errorObject) { this.destination.error(errorObject.e); } else { this.destination.next(x); } } - _error(e) { + _error(e: any) { const result = tryCatch(this.__error)(e); - if (result === errorObject) { + if (result as any === errorObject) { this.destination.error(errorObject.e); } else { this.destination.error(e); @@ -68,7 +69,7 @@ class DoSubscriber extends Subscriber { _complete() { const result = tryCatch(this.__complete)(); - if (result === errorObject) { + if (result as any === errorObject) { this.destination.error(errorObject.e); } else { this.destination.complete(); diff --git a/src/operator/elementAt.ts b/src/operator/elementAt.ts index 6eff62e4d72..a47dbfdccd4 100644 --- a/src/operator/elementAt.ts +++ b/src/operator/elementAt.ts @@ -1,14 +1,15 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {ArgumentOutOfRangeError} from '../util/ArgumentOutOfRangeError'; +import {Observable} from '../Observable'; -export function elementAt(index: number, defaultValue?: any) { +export function elementAt(index: number, defaultValue?: T): Observable { return this.lift(new ElementAtOperator(index, defaultValue)); } -class ElementAtOperator implements Operator { +class ElementAtOperator implements Operator { - constructor(private index: number, private defaultValue?: any) { + constructor(private index: number, private defaultValue?: T) { if (index < 0) { throw new ArgumentOutOfRangeError; } @@ -19,13 +20,13 @@ class ElementAtOperator implements Operator { } } -class ElementAtSubscriber extends Subscriber { +class ElementAtSubscriber extends Subscriber { - constructor(destination: Subscriber, private index: number, private defaultValue?: any) { + constructor(destination: Subscriber, private index: number, private defaultValue?: T) { super(destination); } - _next(x) { + _next(x: T) { if (this.index-- === 0) { this.destination.next(x); this.destination.complete(); diff --git a/src/operator/every.ts b/src/operator/every.ts index 0d73f0a4a83..1af8d78a994 100644 --- a/src/operator/every.ts +++ b/src/operator/every.ts @@ -8,15 +8,13 @@ import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export function every(predicate: (value: T, index: number, source: Observable) => boolean, +export function every(predicate: (value: T, index: number, observable: Observable) => boolean, thisArg?: any): Observable { const source = this; - let result; - if (source._isScalar) { - result = tryCatch(predicate).call(thisArg || this, source.value, 0, source); - if (result === errorObject) { - return new ErrorObservable(errorObject.e, source.scheduler); + let result: boolean = tryCatch(predicate).call(thisArg || this, source.value, 0, source); + if (result as any === errorObject) { + return new ErrorObservable(errorObject.e, source.scheduler); } else { return new ScalarObservable(result, source.scheduler); } @@ -24,9 +22,10 @@ export function every(predicate: (value: T, index: number, source: Observable if (source instanceof ArrayObservable) { const array = (>source).array; - let result = tryCatch((array, predicate, thisArg) => array.every(predicate, thisArg))(array, predicate, thisArg); - if (result === errorObject) { - return new ErrorObservable(errorObject.e, source.scheduler); + let result = tryCatch((array: T[], predicate: (value: T, index: number, observable: Observable) => boolean, thisArg: any) => + array.every(predicate, thisArg))(array, predicate, thisArg); + if (result as any === errorObject) { + return new ErrorObservable(errorObject.e, source.scheduler); } else { return new ScalarObservable(result, source.scheduler); } diff --git a/src/operator/exhaust.ts b/src/operator/exhaust.ts index 806b78491d3..64e9dbb25c8 100644 --- a/src/operator/exhaust.ts +++ b/src/operator/exhaust.ts @@ -9,17 +9,17 @@ export function exhaust(): Observable { return this.lift(new SwitchFirstOperator()); } -class SwitchFirstOperator implements Operator { - call(subscriber: Subscriber): Subscriber { +class SwitchFirstOperator implements Operator { + call(subscriber: Subscriber): Subscriber { return new SwitchFirstSubscriber(subscriber); } } -class SwitchFirstSubscriber extends OuterSubscriber { +class SwitchFirstSubscriber extends OuterSubscriber { private hasSubscription: boolean = false; private hasCompleted: boolean = false; - constructor(destination: Subscriber) { + constructor(destination: Subscriber) { super(destination); } @@ -37,7 +37,7 @@ class SwitchFirstSubscriber extends OuterSubscriber { } } - notifyNext(outerValue: T, innerValue: any): void { + notifyNext(outerValue: T, innerValue: T): void { this.destination.next(innerValue); } diff --git a/src/operator/exhaustMap.ts b/src/operator/exhaustMap.ts index 3a7e80c0b86..cefafacdcef 100644 --- a/src/operator/exhaustMap.ts +++ b/src/operator/exhaustMap.ts @@ -6,35 +6,33 @@ import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export function exhaustMap(project: (value: T, index: number) => Observable, - resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2): Observable { +export function exhaustMap(project: (value: T, index: number) => Observable | Promise, + resultSelector?: ( + outerValue: T, + innerValue: R, + outerIndex: number, + innerIndex: number) => TResult): Observable { return this.lift(new SwitchFirstMapOperator(project, resultSelector)); } -class SwitchFirstMapOperator implements Operator { - constructor(private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2) { +class SwitchFirstMapOperator implements Operator { + constructor(private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber): Subscriber { return new SwitchFirstMapSubscriber(subscriber, this.project, this.resultSelector); } } -class SwitchFirstMapSubscriber extends OuterSubscriber { +class SwitchFirstMapSubscriber extends OuterSubscriber { private hasSubscription: boolean = false; private hasCompleted: boolean = false; private index: number = 0; - constructor(destination: Subscriber, - private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2) { + constructor(destination: Subscriber, + private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { super(destination); } @@ -43,8 +41,8 @@ class SwitchFirstMapSubscriber extends OuterSubscriber { const index = this.index++; const destination = this.destination; let result = tryCatch(this.project)(value, index); - if (result === errorObject) { - destination.error(result.e); + if (result as any === errorObject) { + destination.error(errorObject.e); } else { this.hasSubscription = true; this.add(subscribeToResult(this, result, value, index)); @@ -63,7 +61,7 @@ class SwitchFirstMapSubscriber extends OuterSubscriber { const { resultSelector, destination } = this; if (resultSelector) { const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); } else { destination.next(result); diff --git a/src/operator/expand-support.ts b/src/operator/expand-support.ts index b2716d9d838..6525d419876 100644 --- a/src/operator/expand-support.ts +++ b/src/operator/expand-support.ts @@ -1,5 +1,4 @@ import {Operator} from '../Operator'; -import {Observable} from '../Observable'; import {Scheduler} from '../Scheduler'; import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; @@ -7,9 +6,10 @@ import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {InnerSubscriber} from '../InnerSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; +import {Observable} from '../Observable'; export class ExpandOperator implements Operator { - constructor(private project: (value: T, index: number) => Observable, + constructor(private project: (value: T, index: number) => Observable | Promise, private concurrent: number, private scheduler: Scheduler) { } @@ -26,7 +26,7 @@ export class ExpandSubscriber extends OuterSubscriber { private buffer: any[]; constructor(destination: Subscriber, - private project: (value: T, index: number) => Observable, + private project: (value: T, index: number) => Observable | Promise, private concurrent: number, private scheduler: Scheduler) { super(destination); @@ -51,8 +51,8 @@ export class ExpandSubscriber extends OuterSubscriber { if (this.active < this.concurrent) { destination.next(value); let result = tryCatch(this.project)(value, index); - if (result === errorObject) { - destination.error(result.e); + if (result as any === errorObject) { + destination.error(errorObject.e); } else if (!this.scheduler) { this.subscribeToProjection(result, value, index); } else { @@ -64,7 +64,7 @@ export class ExpandSubscriber extends OuterSubscriber { } } - private subscribeToProjection(result, value: T, index: number): void { + private subscribeToProjection(result: any, value: T, index: number): void { if (result._isScalar) { this._next(result.value); } else { @@ -95,4 +95,4 @@ export class ExpandSubscriber extends OuterSubscriber { notifyNext(outerValue: T, innerValue: R, outerIndex: number, innerIndex: number): void { this._next(innerValue); } -} \ No newline at end of file +} diff --git a/src/operator/expand.ts b/src/operator/expand.ts index e54ce1e0522..ab47416df9b 100644 --- a/src/operator/expand.ts +++ b/src/operator/expand.ts @@ -2,7 +2,7 @@ import {Observable} from '../Observable'; import {Scheduler} from '../Scheduler'; import {ExpandOperator} from './expand-support'; -export function expand(project: (value: T, index: number) => Observable, +export function expand(project: (value: T, index: number) => Observable | Promise, concurrent: number = Number.POSITIVE_INFINITY, scheduler: Scheduler = undefined): Observable { concurrent = (concurrent || 0) < 1 ? Number.POSITIVE_INFINITY : concurrent; diff --git a/src/operator/filter.ts b/src/operator/filter.ts index 754991987b7..cf134392938 100644 --- a/src/operator/filter.ts +++ b/src/operator/filter.ts @@ -2,6 +2,7 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; +import {Observable} from '../Observable'; /** * Similar to the well-known `Array.prototype.filter` method, this operator filters values down to a set @@ -12,12 +13,12 @@ import {errorObject} from '../util/errorObject'; * @param {any} [thisArg] an optional argument to determine the value of `this` in the `select` function * @returns {Observable} an observable of values allowed by the select function */ -export function filter(select: (x: T, ix?: number) => boolean, thisArg?: any) { +export function filter(select: (value: T, index: number) => boolean, thisArg?: any): Observable { return this.lift(new FilterOperator(select, thisArg)); } -class FilterOperator implements Operator { - constructor(private select: (x: T, ix?: number) => boolean, private thisArg?: any) { +class FilterOperator implements Operator { + constructor(private select: (value: T, index: number) => boolean, private thisArg?: any) { } call(subscriber: Subscriber): Subscriber { @@ -28,14 +29,13 @@ class FilterOperator implements Operator { class FilterSubscriber extends Subscriber { count: number = 0; - select: (x: T, ix?: number) => boolean; - constructor(destination: Subscriber, select: (x: T, ix?: number) => boolean, private thisArg: any) { + constructor(destination: Subscriber, private select: (value: T, index: number) => boolean, private thisArg: any) { super(destination); this.select = select; } - _next(x) { + _next(x: T) { const result = tryCatch(this.select).call(this.thisArg || this, x, this.count++); if (result === errorObject) { this.destination.error(errorObject.e); diff --git a/src/operator/finally.ts b/src/operator/finally.ts index 766ed6e6503..89fe2407c4a 100644 --- a/src/operator/finally.ts +++ b/src/operator/finally.ts @@ -1,12 +1,13 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {Subscription} from '../Subscription'; +import {Observable} from '../Observable'; -export function _finally(finallySelector: () => void) { +export function _finally(finallySelector: () => void): Observable { return this.lift(new FinallyOperator(finallySelector)); } -class FinallyOperator implements Operator { +class FinallyOperator implements Operator { constructor(private finallySelector: () => void) { } diff --git a/src/operator/find-support.ts b/src/operator/find-support.ts index 6cd7f430a98..328dd202eb4 100644 --- a/src/operator/find-support.ts +++ b/src/operator/find-support.ts @@ -5,8 +5,8 @@ import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export class FindValueOperator implements Operator { - constructor(private predicate: (value: T, index: number, source: Observable) => boolean, +export class FindValueOperator implements Operator { + constructor(private predicate: (value: T, index: number, observable: Observable) => boolean, private source: Observable, private yieldIndex: boolean, private thisArg?: any) { @@ -21,7 +21,7 @@ export class FindValueSubscriber extends Subscriber { private index: number = 0; constructor(destination: Subscriber, - private predicate: (value: T, index: number, source: Observable) => boolean, + private predicate: (value: T, index: number, observable: Observable) => boolean, private source: Observable, private yieldIndex: boolean, private thisArg?: any) { @@ -49,4 +49,4 @@ export class FindValueSubscriber extends Subscriber { _complete(): void { this.notifyComplete(this.yieldIndex ? -1 : undefined); } -} \ No newline at end of file +} diff --git a/src/operator/find.ts b/src/operator/find.ts index 568532f66eb..3af4862275d 100644 --- a/src/operator/find.ts +++ b/src/operator/find.ts @@ -1,7 +1,7 @@ -import {FindValueOperator} from './find-support'; import {Observable} from '../Observable'; +import {FindValueOperator} from './find-support'; -export function find(predicate: (value: T, index: number, source: Observable) => boolean, thisArg?: any): Observable { +export function find(predicate: (value: T, index: number, observable: Observable) => boolean, thisArg?: any): Observable { if (typeof predicate !== 'function') { throw new TypeError('predicate is not a function'); } diff --git a/src/operator/findIndex.ts b/src/operator/findIndex.ts index e857cd163c9..b46705b1606 100644 --- a/src/operator/findIndex.ts +++ b/src/operator/findIndex.ts @@ -1,6 +1,6 @@ import {Observable} from '../Observable'; import {FindValueOperator} from './find-support'; -export function findIndex(predicate: (value: T, index: number, source: Observable) => boolean, thisArg?: any): Observable { +export function findIndex(predicate: (value: T, index: number, observable: Observable) => boolean, thisArg?: any): Observable { return this.lift(new FindValueOperator(predicate, this, true, thisArg)); } diff --git a/src/operator/first.ts b/src/operator/first.ts index 9d6c1f22e6b..22af8d35bbf 100644 --- a/src/operator/first.ts +++ b/src/operator/first.ts @@ -5,14 +5,14 @@ import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; import {EmptyError} from '../util/EmptyError'; -export function first(predicate?: (value: T, index: number, source: Observable) => boolean, +export function first(predicate?: (value: T, index: number, observable: Observable) => boolean, resultSelector?: (value: T, index: number) => R, - defaultValue?: any): Observable | Observable { + defaultValue?: R): Observable { return this.lift(new FirstOperator(predicate, resultSelector, defaultValue, this)); } class FirstOperator implements Operator { - constructor(private predicate?: (value: T, index: number, source: Observable) => boolean, + constructor(private predicate?: (value: T, index: number, observable: Observable) => boolean, private resultSelector?: (value: T, index: number) => R, private defaultValue?: any, private source?: Observable) { @@ -28,7 +28,7 @@ class FirstSubscriber extends Subscriber { private hasCompleted: boolean = false; constructor(destination: Subscriber, - private predicate?: (value: T, index: number, source: Observable) => boolean, + private predicate?: (value: T, index: number, observable: Observable) => boolean, private resultSelector?: (value: T, index: number) => R, private defaultValue?: any, private source?: Observable) { @@ -49,7 +49,7 @@ class FirstSubscriber extends Subscriber { if (passed) { if (resultSelector) { let result = tryCatch(resultSelector)(value, index); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); return; } diff --git a/src/operator/groupBy-support.ts b/src/operator/groupBy-support.ts index 71d3dbfc8f6..5625fafafc9 100644 --- a/src/operator/groupBy-support.ts +++ b/src/operator/groupBy-support.ts @@ -27,8 +27,8 @@ export class RefCountSubscription extends Subscription { } } -export class GroupedObservable extends Observable { - constructor(public key: string, +export class GroupedObservable extends Observable { + constructor(public key: TKey, private groupSubject: Subject, private refCountSubscription?: RefCountSubscription) { super(); @@ -61,4 +61,3 @@ export class InnerRefCountSubscription extends Subscription { } } } - diff --git a/src/operator/groupBy.ts b/src/operator/groupBy.ts index 9f23450520a..4c209dc3311 100644 --- a/src/operator/groupBy.ts +++ b/src/operator/groupBy.ts @@ -8,21 +8,21 @@ import {RefCountSubscription, GroupedObservable} from './groupBy-support'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export function groupBy(keySelector: (value: T) => string, - elementSelector?: (value: T) => R, - durationSelector?: (grouped: GroupedObservable) => Observable): GroupByObservable { - return new GroupByObservable(this, keySelector, elementSelector, durationSelector); +export function groupBy(keySelector: (value: T) => TKey, + elementSelector?: (value: T) => R, + durationSelector?: (grouped: GroupedObservable) => Observable): GroupByObservable { + return new GroupByObservable(this, keySelector, elementSelector, durationSelector); } -export class GroupByObservable extends Observable> { +export class GroupByObservable extends Observable> { constructor(public source: Observable, - private keySelector: (value: T) => string, + private keySelector: (value: T) => TKey, private elementSelector?: (value: T) => R, - private durationSelector?: (grouped: GroupedObservable) => Observable) { + private durationSelector?: (grouped: GroupedObservable) => Observable) { super(); } - _subscribe(subscriber: Subscriber): Subscription | Function | void { + _subscribe(subscriber: Subscriber): Subscription { const refCountSubscription = new RefCountSubscription(); const groupBySubscriber = new GroupBySubscriber( subscriber, refCountSubscription, this.keySelector, this.elementSelector, this.durationSelector @@ -32,14 +32,14 @@ export class GroupByObservable extends Observable> { } } -class GroupBySubscriber extends Subscriber { - private groups = null; +class GroupBySubscriber extends Subscriber { + private groups: Map> = null; constructor(destination: Subscriber, private refCountSubscription: RefCountSubscription, - private keySelector: (value: T) => string, + private keySelector: (value: T) => TKey, private elementSelector?: (value: T) => R, - private durationSelector?: (grouped: GroupedObservable) => Observable) { + private durationSelector?: (grouped: GroupedObservable) => Observable) { super(); this.destination = destination; this.add(destination); @@ -47,8 +47,8 @@ class GroupBySubscriber extends Subscriber { _next(x: T): void { let key = tryCatch(this.keySelector)(x); - if (key === errorObject) { - this.error(key.e); + if (key as any === errorObject) { + this.error(errorObject.e); } else { let groups = this.groups; const elementSelector = this.elementSelector; @@ -58,16 +58,16 @@ class GroupBySubscriber extends Subscriber { groups = this.groups = typeof key === 'string' ? new FastMap() : new Map(); } - let group: Subject = groups.get(key); + let group = groups.get(key); if (!group) { - groups.set(key, group = new Subject()); - let groupedObservable = new GroupedObservable(key, group, this.refCountSubscription); + groups.set(key, group = new Subject()); + let groupedObservable = new GroupedObservable(key, group, this.refCountSubscription); if (durationSelector) { - let duration = tryCatch(durationSelector)(new GroupedObservable(key, group)); - if (duration === errorObject) { - this.error(duration.e); + let duration = tryCatch(durationSelector)(new GroupedObservable(key, group)); + if (duration as any === errorObject) { + this.error(errorObject.e); } else { this.add(duration._subscribe(new GroupDurationSubscriber(key, group, this))); } @@ -78,8 +78,8 @@ class GroupBySubscriber extends Subscriber { if (elementSelector) { let value = tryCatch(elementSelector)(x); - if (value === errorObject) { - this.error(value.e); + if (value as any === errorObject) { + this.error(errorObject.e); } else { group.next(value); } @@ -105,21 +105,21 @@ class GroupBySubscriber extends Subscriber { if (groups) { groups.forEach((group, key) => { group.complete(); - this.removeGroup(group); + this.removeGroup(key); }); } this.destination.complete(); } - removeGroup(key: string): void { + removeGroup(key: TKey): void { this.groups.delete(key); } } -class GroupDurationSubscriber extends Subscriber { - constructor(private key: string, +class GroupDurationSubscriber extends Subscriber { + constructor(private key: TKey, private group: Subject, - private parent: GroupBySubscriber) { + private parent: GroupBySubscriber) { super(null); } diff --git a/src/operator/ignoreElements.ts b/src/operator/ignoreElements.ts index 0ef9f355407..3499dcf31a7 100644 --- a/src/operator/ignoreElements.ts +++ b/src/operator/ignoreElements.ts @@ -1,8 +1,9 @@ +import {Observable} from '../Observable'; import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {noop} from '../util/noop'; -export function ignoreElements() { +export function ignoreElements(): Observable { return this.lift(new IgnoreElementsOperator()); }; diff --git a/src/operator/inspectTime.ts b/src/operator/inspectTime.ts index ed726ddd54c..355a5da4be0 100644 --- a/src/operator/inspectTime.ts +++ b/src/operator/inspectTime.ts @@ -38,7 +38,7 @@ class InspectTimeSubscriber extends Subscriber { } } -function dispatchNotification(state) { +function dispatchNotification(state: any) { let { subscriber, delay } = state; subscriber.notifyNext(); (this).schedule(state, delay); diff --git a/src/operator/isEmpty.ts b/src/operator/isEmpty.ts index 12507f61610..4f18cdde658 100644 --- a/src/operator/isEmpty.ts +++ b/src/operator/isEmpty.ts @@ -1,19 +1,20 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; +import {Observable} from '../Observable'; -export function isEmpty() { +export function isEmpty(): Observable { return this.lift(new IsEmptyOperator()); } -class IsEmptyOperator implements Operator { - call (observer: Subscriber): Subscriber { - return new IsEmptySubscriber(observer); +class IsEmptyOperator implements Operator { + call (observer: Subscriber): Subscriber { + return new IsEmptySubscriber(observer); } } -class IsEmptySubscriber extends Subscriber { +class IsEmptySubscriber extends Subscriber { - constructor(destination: Subscriber) { + constructor(destination: Subscriber) { super(destination); } @@ -24,7 +25,7 @@ class IsEmptySubscriber extends Subscriber { destination.complete(); } - _next(value: T) { + _next(value: boolean) { this.notifyComplete(false); } diff --git a/src/operator/last.ts b/src/operator/last.ts index 66894381029..43b0d7700be 100644 --- a/src/operator/last.ts +++ b/src/operator/last.ts @@ -5,14 +5,14 @@ import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; import {EmptyError} from '../util/EmptyError'; -export function last(predicate?: (value: T, index: number, source: Observable) => boolean, +export function last(predicate?: (value: T, index: number, observable: Observable) => boolean, resultSelector?: (value: T, index: number) => R, - defaultValue?: any): Observable | Observable { + defaultValue?: R): Observable { return this.lift(new LastOperator(predicate, resultSelector, defaultValue, this)); } class LastOperator implements Operator { - constructor(private predicate?: (value: T, index: number, source: Observable) => boolean, + constructor(private predicate?: (value: T, index: number, observable: Observable) => boolean, private resultSelector?: (value: T, index: number) => R, private defaultValue?: any, private source?: Observable) { @@ -24,12 +24,12 @@ class LastOperator implements Operator { } class LastSubscriber extends Subscriber { - private lastValue: T; + private lastValue: T | R; private hasValue: boolean = false; private index: number = 0; constructor(destination: Subscriber, - private predicate?: (value: T, index: number, source: Observable) => boolean, + private predicate?: (value: T, index: number, observable: Observable) => boolean, private resultSelector?: (value: T, index: number) => R, private defaultValue?: any, private source?: Observable) { @@ -46,7 +46,7 @@ class LastSubscriber extends Subscriber { if (predicate) { let found = tryCatch(predicate)(value, index, this.source); - if (found === errorObject) { + if (found as any === errorObject) { destination.error(errorObject.e); return; } @@ -54,7 +54,7 @@ class LastSubscriber extends Subscriber { if (found) { if (resultSelector) { let result = tryCatch(resultSelector)(value, index); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); return; } diff --git a/src/operator/map.ts b/src/operator/map.ts index aeb3ea6da85..52c3f89aeb8 100644 --- a/src/operator/map.ts +++ b/src/operator/map.ts @@ -12,7 +12,7 @@ import {errorObject} from '../util/errorObject'; * @param {any} [thisArg] an optional argument to define what `this` is in the project function * @returns {Observable} a observable of projected values */ -export function map(project: (x: T, ix?: number) => R, thisArg?: any): Observable { +export function map(project: (value: T, index: number) => R, thisArg?: any): Observable { if (typeof project !== 'function') { throw new TypeError('argument is not a function. Are you looking for `mapTo()`?'); } @@ -20,7 +20,7 @@ export function map(project: (x: T, ix?: number) => R, thisArg?: any): Obs } class MapOperator implements Operator { - constructor(private project: (x: T, ix?: number) => R, private thisArg: any) { + constructor(private project: (value: T, index: number) => R, private thisArg: any) { } call(subscriber: Subscriber): Subscriber { @@ -32,12 +32,12 @@ class MapSubscriber extends Subscriber { count: number = 0; constructor(destination: Subscriber, - private project: (x: T, ix?: number) => R, + private project: (value: T, index: number) => R, private thisArg: any) { super(destination); } - _next(x) { + _next(x: T) { const result = tryCatch(this.project).call(this.thisArg || this, x, this.count++); if (result === errorObject) { this.error(errorObject.e); diff --git a/src/operator/mapTo.ts b/src/operator/mapTo.ts index 0d6b7a0fca3..cf9cc5affdb 100644 --- a/src/operator/mapTo.ts +++ b/src/operator/mapTo.ts @@ -1,12 +1,13 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; +import {Observable} from '../Observable'; /** * Maps every value to the same value every time. * @param {any} value the value to map each incoming value to * @returns {Observable} an observable of the passed value that emits everytime the source does */ -export function mapTo(value: R) { +export function mapTo(value: R): Observable { return this.lift(new MapToOperator(value)); } @@ -32,7 +33,7 @@ class MapToSubscriber extends Subscriber { this.value = value; } - _next(x) { + _next(x: T) { this.destination.next(this.value); } } diff --git a/src/operator/materialize.ts b/src/operator/materialize.ts index fbfb5fa95e5..c937a2fc55e 100644 --- a/src/operator/materialize.ts +++ b/src/operator/materialize.ts @@ -7,14 +7,14 @@ export function materialize(): Observable> { return this.lift(new MaterializeOperator()); } -class MaterializeOperator implements Operator { - call(subscriber: Subscriber): Subscriber { +class MaterializeOperator implements Operator> { + call(subscriber: Subscriber>): Subscriber { return new MaterializeSubscriber(subscriber); } } class MaterializeSubscriber extends Subscriber { - constructor(destination: Subscriber) { + constructor(destination: Subscriber>) { super(destination); } diff --git a/src/operator/max.ts b/src/operator/max.ts index ad883408539..eb625de16b1 100644 --- a/src/operator/max.ts +++ b/src/operator/max.ts @@ -1,8 +1,8 @@ import {Observable} from '../Observable'; import {ReduceOperator} from './reduce-support'; -export function max(comparer?: (x: R, y: T) => R): Observable { - const max = (typeof comparer === 'function') +export function max(comparer?: (value1: T, value2: T) => T): Observable { + const max: typeof comparer = (typeof comparer === 'function') ? comparer : (x, y) => x > y ? x : y; return this.lift(new ReduceOperator(max)); diff --git a/src/operator/merge-static.ts b/src/operator/merge-static.ts index b53566054ee..b4dda49cf17 100644 --- a/src/operator/merge-static.ts +++ b/src/operator/merge-static.ts @@ -5,7 +5,7 @@ import {MergeAllOperator} from './mergeAll-support'; import {queue} from '../scheduler/queue'; import {isScheduler} from '../util/isScheduler'; -export function merge(...observables: Array | Scheduler | number>): Observable { +export function merge(...observables: Array | Scheduler | number>): Observable { let concurrent = Number.POSITIVE_INFINITY; let scheduler: Scheduler = queue; let last: any = observables[observables.length - 1]; @@ -22,5 +22,5 @@ export function merge(...observables: Array | Scheduler | num return >observables[0]; } - return new ArrayObservable(observables, scheduler).lift(new MergeAllOperator(concurrent)); + return new ArrayObservable>(observables, scheduler).lift, R>(new MergeAllOperator(concurrent)); } diff --git a/src/operator/merge.ts b/src/operator/merge.ts index 9577b97df2c..0a824c989ee 100644 --- a/src/operator/merge.ts +++ b/src/operator/merge.ts @@ -2,7 +2,7 @@ import {Observable} from '../Observable'; import {merge as mergeStatic} from './merge-static'; import {Scheduler} from '../Scheduler'; -export function merge(...observables: (Observable|Scheduler|number)[]): Observable { +export function merge(...observables: Array | Scheduler | number>): Observable { observables.unshift(this); return mergeStatic.apply(this, observables); } diff --git a/src/operator/mergeAll-support.ts b/src/operator/mergeAll-support.ts index 0ba4233f551..a1e57b2a7ea 100644 --- a/src/operator/mergeAll-support.ts +++ b/src/operator/mergeAll-support.ts @@ -5,7 +5,7 @@ import {Subscription} from '../Subscription'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export class MergeAllOperator implements Operator { +export class MergeAllOperator implements Operator, T> { constructor(private concurrent: number) { } @@ -14,22 +14,22 @@ export class MergeAllOperator implements Operator { } } -export class MergeAllSubscriber extends OuterSubscriber { +export class MergeAllSubscriber extends OuterSubscriber, T> { private hasCompleted: boolean = false; - private buffer: Observable[] = []; + private buffer: Observable[] = []; private active: number = 0; constructor(destination: Observer, private concurrent: number) { super(destination); } - _next(observable: any) { + _next(observable: Observable) { if (this.active < this.concurrent) { if (observable._isScalar) { - this.destination.next(observable.value); + this.destination.next((observable as any).value); } else { this.active++; - this.add(subscribeToResult(this, observable)); + this.add(subscribeToResult, T>(this, observable)); } } else { this.buffer.push(observable); @@ -53,4 +53,4 @@ export class MergeAllSubscriber extends OuterSubscriber { this.destination.complete(); } } -} \ No newline at end of file +} diff --git a/src/operator/mergeAll.ts b/src/operator/mergeAll.ts index e99da95648e..337dfa9efa4 100644 --- a/src/operator/mergeAll.ts +++ b/src/operator/mergeAll.ts @@ -1,6 +1,5 @@ -import {Observable} from '../Observable'; import {MergeAllOperator} from './mergeAll-support'; -export function mergeAll(concurrent: number = Number.POSITIVE_INFINITY): Observable { +export function mergeAll(concurrent: number = Number.POSITIVE_INFINITY): T { return this.lift(new MergeAllOperator(concurrent)); } diff --git a/src/operator/mergeMap-support.ts b/src/operator/mergeMap-support.ts index 57035981f6b..2bac40a2cd9 100644 --- a/src/operator/mergeMap-support.ts +++ b/src/operator/mergeMap-support.ts @@ -7,9 +7,9 @@ import {errorObject} from '../util/errorObject'; import {subscribeToResult} from '../util/subscribeToResult'; import {OuterSubscriber} from '../OuterSubscriber'; -export class MergeMapOperator implements Operator { - constructor(private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2, +export class MergeMapOperator implements Operator { + constructor(private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult, private concurrent: number = Number.POSITIVE_INFINITY) { } @@ -20,15 +20,15 @@ export class MergeMapOperator implements Operator { } } -export class MergeMapSubscriber extends OuterSubscriber { +export class MergeMapSubscriber extends OuterSubscriber { private hasCompleted: boolean = false; private buffer: Observable[] = []; private active: number = 0; protected index: number = 0; constructor(destination: Subscriber, - private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2, + private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult, private concurrent: number = Number.POSITIVE_INFINITY) { super(destination); } @@ -38,8 +38,8 @@ export class MergeMapSubscriber extends OuterSubscriber { const index = this.index++; const ish = tryCatch(this.project)(value, index); const destination = this.destination; - if (ish === errorObject) { - destination.error(ish.e); + if (ish as any === errorObject) { + destination.error(errorObject.e); } else { this.active++; this._innerSub(ish, value, index); @@ -64,7 +64,7 @@ export class MergeMapSubscriber extends OuterSubscriber { const { destination, resultSelector } = this; if (resultSelector) { const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); } else { destination.next(result); @@ -84,4 +84,4 @@ export class MergeMapSubscriber extends OuterSubscriber { this.destination.complete(); } } -} \ No newline at end of file +} diff --git a/src/operator/mergeMap.ts b/src/operator/mergeMap.ts index 2ec6977d2f4..6ab6f653959 100644 --- a/src/operator/mergeMap.ts +++ b/src/operator/mergeMap.ts @@ -1,11 +1,8 @@ import {Observable} from '../Observable'; import {MergeMapOperator} from './mergeMap-support'; -export function mergeMap(project: (value: T, index: number) => Observable, - resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R, - concurrent: number = Number.POSITIVE_INFINITY) { - return this.lift(new MergeMapOperator(project, resultSelector, concurrent)); +export function mergeMap(project: (value: T, index: number) => Observable | Promise, + resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult | number, + concurrent: number = Number.POSITIVE_INFINITY): Observable { + return this.lift(new MergeMapOperator(project, resultSelector, concurrent)); } diff --git a/src/operator/mergeMapTo-support.ts b/src/operator/mergeMapTo-support.ts index eadcbab5418..1d1c977e687 100644 --- a/src/operator/mergeMapTo-support.ts +++ b/src/operator/mergeMapTo-support.ts @@ -8,13 +8,13 @@ import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; import {InnerSubscriber} from '../InnerSubscriber'; -export class MergeMapToOperator implements Operator { - constructor(private ish: any, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2, +export class MergeMapToOperator implements Operator, TResult> { + constructor(private ish: Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult, private concurrent: number = Number.POSITIVE_INFINITY) { } - call(observer: Subscriber): Subscriber { + call(observer: Subscriber): Subscriber { return new MergeMapToSubscriber(observer, this.ish, this.resultSelector, this.concurrent); } } @@ -25,13 +25,12 @@ export class MergeMapToSubscriber extends OuterSubscriber { private active: number = 0; protected index: number = 0; - constructor(destination: Subscriber, - private ish: any, + constructor(destination: Subscriber, + private ish: Observable | Promise, private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2, private concurrent: number = Number.POSITIVE_INFINITY) { super(destination); } - _next(value: any): void { if (this.active < this.concurrent) { const resultSelector = this.resultSelector; @@ -65,7 +64,7 @@ export class MergeMapToSubscriber extends OuterSubscriber { const { resultSelector, destination } = this; if (resultSelector) { const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); } else { destination.next(result); @@ -89,4 +88,4 @@ export class MergeMapToSubscriber extends OuterSubscriber { this.destination.complete(); } } -} \ No newline at end of file +} diff --git a/src/operator/mergeMapTo.ts b/src/operator/mergeMapTo.ts index a111a38ba27..21046fde392 100644 --- a/src/operator/mergeMapTo.ts +++ b/src/operator/mergeMapTo.ts @@ -1,11 +1,8 @@ import {Observable} from '../Observable'; import {MergeMapToOperator} from './mergeMapTo-support'; -export function mergeMapTo(observable: Observable, - resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2, - concurrent: number = Number.POSITIVE_INFINITY): Observable { - return this.lift(new MergeMapToOperator(observable, resultSelector, concurrent)); +export function mergeMapTo(observable: Observable, + resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult | number, + concurrent: number = Number.POSITIVE_INFINITY): Observable { + return this.lift(new MergeMapToOperator(observable, resultSelector, concurrent)); } diff --git a/src/operator/mergeScan.ts b/src/operator/mergeScan.ts index 691e6ebf7f3..8fc03cd5a4b 100644 --- a/src/operator/mergeScan.ts +++ b/src/operator/mergeScan.ts @@ -7,14 +7,14 @@ import {errorObject} from '../util/errorObject'; import {subscribeToResult} from '../util/subscribeToResult'; import {OuterSubscriber} from '../OuterSubscriber'; -export function mergeScan(project: (acc: R, x: T) => Observable, +export function mergeScan(project: (acc: R, value: T) => Observable, seed: R, - concurrent: number = Number.POSITIVE_INFINITY) { + concurrent: number = Number.POSITIVE_INFINITY): Observable { return this.lift(new MergeScanOperator(project, seed, concurrent)); } export class MergeScanOperator implements Operator { - constructor(private project: (acc: R, x: T) => Observable, + constructor(private project: (acc: R, value: T) => Observable, private seed: R, private concurrent: number) { } @@ -34,7 +34,7 @@ export class MergeScanSubscriber extends OuterSubscriber { protected index: number = 0; constructor(destination: Subscriber, - private project: (acc: R, x: T) => Observable, + private project: (acc: R, value: T) => Observable, private acc: R, private concurrent: number) { super(destination); @@ -45,8 +45,8 @@ export class MergeScanSubscriber extends OuterSubscriber { const index = this.index++; const ish = tryCatch(this.project)(this.acc, value); const destination = this.destination; - if (ish === errorObject) { - destination.error(ish.e); + if (ish as any === errorObject) { + destination.error(errorObject.e); } else { this.active++; this._innerSub(ish, value, index); diff --git a/src/operator/min.ts b/src/operator/min.ts index eb5d382c6f8..ffb3755a4fc 100644 --- a/src/operator/min.ts +++ b/src/operator/min.ts @@ -1,8 +1,8 @@ import {Observable} from '../Observable'; import {ReduceOperator} from './reduce-support'; -export function min(comparer?: (x: R, y: T) => R): Observable { - const min = (typeof comparer === 'function') +export function min(comparer?: (value1: T, value2: T) => T): Observable { + const min: typeof comparer = (typeof comparer === 'function') ? comparer : (x, y) => x < y ? x : y; return this.lift(new ReduceOperator(min)); diff --git a/src/operator/multicast.ts b/src/operator/multicast.ts index f645e64d240..3f0ee213241 100644 --- a/src/operator/multicast.ts +++ b/src/operator/multicast.ts @@ -1,7 +1,7 @@ import {Subject} from '../Subject'; import {ConnectableObservable} from '../observable/ConnectableObservable'; -export function multicast(subjectOrSubjectFactory: Subject|(() => Subject)) { +export function multicast(subjectOrSubjectFactory: Subject | (() => Subject)): ConnectableObservable { let subjectFactory: () => Subject; if (typeof subjectOrSubjectFactory === 'function') { subjectFactory = <() => Subject>subjectOrSubjectFactory; diff --git a/src/operator/observeOn-support.ts b/src/operator/observeOn-support.ts index d5c05bdc7a4..7e3ff5f5816 100644 --- a/src/operator/observeOn-support.ts +++ b/src/operator/observeOn-support.ts @@ -4,7 +4,7 @@ import {Observer} from '../Observer'; import {Subscriber} from '../Subscriber'; import {Notification} from '../Notification'; -export class ObserveOnOperator implements Operator { +export class ObserveOnOperator implements Operator { constructor(private scheduler: Scheduler, private delay: number = 0) { } diff --git a/src/operator/partition.ts b/src/operator/partition.ts index 6bb26325ba9..000196116d7 100644 --- a/src/operator/partition.ts +++ b/src/operator/partition.ts @@ -2,7 +2,7 @@ import {not} from '../util/not'; import {filter} from './filter'; import {Observable} from '../Observable'; -export function partition(predicate: (x: any, i?: any, a?: any) => boolean, thisArg?: any): Observable[] { +export function partition(predicate: (value: T) => boolean, thisArg?: any): [Observable, Observable] { return [ filter.call(this, predicate), filter.call(this, not(predicate, thisArg)) diff --git a/src/operator/publish.ts b/src/operator/publish.ts index 03596a6f417..c694996717b 100644 --- a/src/operator/publish.ts +++ b/src/operator/publish.ts @@ -1,6 +1,7 @@ import {Subject} from '../Subject'; import {multicast} from './multicast'; +import {ConnectableObservable} from '../observable/ConnectableObservable'; -export function publish() { - return multicast.call(this, new Subject()); +export function publish(): ConnectableObservable { + return multicast.call(this, new Subject()); } diff --git a/src/operator/publishBehavior.ts b/src/operator/publishBehavior.ts index 09c7613f87c..70030175f0c 100644 --- a/src/operator/publishBehavior.ts +++ b/src/operator/publishBehavior.ts @@ -1,6 +1,7 @@ import {BehaviorSubject} from '../subject/BehaviorSubject'; import {multicast} from './multicast'; +import {ConnectableObservable} from '../observable/ConnectableObservable'; -export function publishBehavior(value: any) { - return multicast.call(this, new BehaviorSubject(value)); +export function publishBehavior(value: T): ConnectableObservable { + return multicast.call(this, new BehaviorSubject(value)); } diff --git a/src/operator/publishLast.ts b/src/operator/publishLast.ts index a2d6bee7468..2f02a35ae61 100644 --- a/src/operator/publishLast.ts +++ b/src/operator/publishLast.ts @@ -3,5 +3,5 @@ import {multicast} from './multicast'; import {ConnectableObservable} from '../observable/ConnectableObservable'; export function publishLast(): ConnectableObservable { - return multicast.call(this, new AsyncSubject()); -} \ No newline at end of file + return multicast.call(this, new AsyncSubject()); +} diff --git a/src/operator/publishReplay.ts b/src/operator/publishReplay.ts index b3714b4e949..556c7539d51 100644 --- a/src/operator/publishReplay.ts +++ b/src/operator/publishReplay.ts @@ -1,9 +1,10 @@ import {ReplaySubject} from '../subject/ReplaySubject'; import {Scheduler} from '../Scheduler'; import {multicast} from './multicast'; +import {ConnectableObservable} from '../observable/ConnectableObservable'; -export function publishReplay(bufferSize: number = Number.POSITIVE_INFINITY, - windowTime: number = Number.POSITIVE_INFINITY, - scheduler?: Scheduler) { - return multicast.call(this, new ReplaySubject(bufferSize, windowTime, scheduler)); +export function publishReplay(bufferSize: number = Number.POSITIVE_INFINITY, + windowTime: number = Number.POSITIVE_INFINITY, + scheduler?: Scheduler): ConnectableObservable { + return multicast.call(this, new ReplaySubject(bufferSize, windowTime, scheduler)); } diff --git a/src/operator/reduce-support.ts b/src/operator/reduce-support.ts index 4654c39113e..ce7f57c662c 100644 --- a/src/operator/reduce-support.ts +++ b/src/operator/reduce-support.ts @@ -5,7 +5,7 @@ import {errorObject} from '../util/errorObject'; export class ReduceOperator implements Operator { - constructor(private project: (acc: R, x: T) => R, private seed?: R) { + constructor(private project: (acc: R, value: T) => R, private seed?: R) { } call(subscriber: Subscriber): Subscriber { @@ -15,19 +15,19 @@ export class ReduceOperator implements Operator { export class ReduceSubscriber extends Subscriber { - acc: R; + acc: T | R; hasSeed: boolean; hasValue: boolean = false; - project: (acc: R, x: T) => R; + project: (acc: R, value: T) => R; - constructor(destination: Subscriber, project: (acc: R, x: T) => R, seed?: R) { + constructor(destination: Subscriber, project: (acc: R, value: T) => R, seed?: R) { super(destination); this.acc = seed; this.project = project; this.hasSeed = typeof seed !== 'undefined'; } - _next(x) { + _next(x: T) { if (this.hasValue || (this.hasValue = this.hasSeed)) { const result = tryCatch(this.project).call(this, this.acc, x); if (result === errorObject) { diff --git a/src/operator/reduce.ts b/src/operator/reduce.ts index 52070f61ae6..7226ba1b78d 100644 --- a/src/operator/reduce.ts +++ b/src/operator/reduce.ts @@ -1,6 +1,6 @@ import {Observable} from '../Observable'; import {ReduceOperator} from './reduce-support'; -export function reduce(project: (acc: R, x: T) => R, seed?: R): Observable { +export function reduce(project: (acc: R, value: T) => R, seed?: R): Observable { return this.lift(new ReduceOperator(project, seed)); } diff --git a/src/operator/repeat.ts b/src/operator/repeat.ts index d2296e964bf..b63471eb47f 100644 --- a/src/operator/repeat.ts +++ b/src/operator/repeat.ts @@ -6,13 +6,13 @@ import {Subscription} from '../Subscription'; export function repeat(count: number = -1): Observable { if (count === 0) { - return new EmptyObservable(); + return new EmptyObservable(); } else { return this.lift(new RepeatOperator(count, this)); } } -class RepeatOperator implements Operator { +class RepeatOperator implements Operator { constructor(private count: number, private source: Observable) { } diff --git a/src/operator/retry.ts b/src/operator/retry.ts index 4fed734503a..5cae2cb9709 100644 --- a/src/operator/retry.ts +++ b/src/operator/retry.ts @@ -7,13 +7,13 @@ export function retry(count: number = 0): Observable { return this.lift(new RetryOperator(count, this)); } -class RetryOperator implements Operator { +class RetryOperator implements Operator { constructor(private count: number, protected source: Observable) { } call(subscriber: Subscriber): Subscriber { - return new FirstRetrySubscriber(subscriber, this.count, this.source); + return new FirstRetrySubscriber(subscriber, this.count, this.source); } } @@ -32,7 +32,7 @@ class FirstRetrySubscriber extends Subscriber { this.destination.next(value); } - error(error?) { + error(error: any) { if (!this.isUnsubscribed) { this.unsubscribe(); this.resubscribe(); diff --git a/src/operator/retryWhen.ts b/src/operator/retryWhen.ts index 1f58285f4f9..7f30b631306 100644 --- a/src/operator/retryWhen.ts +++ b/src/operator/retryWhen.ts @@ -6,17 +6,17 @@ import {Subscription} from '../Subscription'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export function retryWhen(notifier: (errors: Observable) => Observable) { +export function retryWhen(notifier: (errors: Observable) => Observable): Observable { return this.lift(new RetryWhenOperator(notifier, this)); } -class RetryWhenOperator implements Operator { +class RetryWhenOperator implements Operator { constructor(protected notifier: (errors: Observable) => Observable, protected source: Observable) { } call(subscriber: Subscriber): Subscriber { - return new FirstRetryWhenSubscriber(subscriber, this.notifier, this.source); + return new FirstRetryWhenSubscriber(subscriber, this.notifier, this.source); } } @@ -38,7 +38,7 @@ class FirstRetryWhenSubscriber extends Subscriber { this.destination.next(value); } - error(err?) { + error(err: any) { const destination = this.destination; if (!this.isUnsubscribed) { super.unsubscribe(); diff --git a/src/operator/sample.ts b/src/operator/sample.ts index ef3b55fafca..a3f1cfaf80d 100644 --- a/src/operator/sample.ts +++ b/src/operator/sample.ts @@ -6,11 +6,11 @@ export function sample(notifier: Observable): Observable { return this.lift(new SampleOperator(notifier)); } -class SampleOperator implements Operator { +class SampleOperator implements Operator { constructor(private notifier: Observable) { } - call(subscriber: Subscriber) { + call(subscriber: Subscriber) { return new SampleSubscriber(subscriber, this.notifier); } } @@ -19,7 +19,7 @@ class SampleSubscriber extends Subscriber { private lastValue: T; private hasValue: boolean = false; - constructor(destination: Subscriber, private notifier: Observable) { + constructor(destination: Subscriber, private notifier: any) { super(destination); this.add(notifier._subscribe(new SampleNotificationSubscriber(this))); } diff --git a/src/operator/sampleTime.ts b/src/operator/sampleTime.ts index 2877a763077..b331aab2295 100644 --- a/src/operator/sampleTime.ts +++ b/src/operator/sampleTime.ts @@ -8,11 +8,11 @@ export function sampleTime(delay: number, scheduler: Scheduler = asap): Obser return this.lift(new SampleTimeOperator(delay, scheduler)); } -class SampleTimeOperator implements Operator { +class SampleTimeOperator implements Operator { constructor(private delay: number, private scheduler: Scheduler) { } - call(subscriber: Subscriber) { + call(subscriber: Subscriber) { return new SampleTimeSubscriber(subscriber, this.delay, this.scheduler); } } @@ -39,7 +39,7 @@ class SampleTimeSubscriber extends Subscriber { } } -function dispatchNotification(state) { +function dispatchNotification(state: any) { let { subscriber, delay } = state; subscriber.notifyNext(); (this).schedule(state, delay); diff --git a/src/operator/scan.ts b/src/operator/scan.ts index a014bc04b17..ad93476da07 100644 --- a/src/operator/scan.ts +++ b/src/operator/scan.ts @@ -4,7 +4,7 @@ import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export function scan(accumulator: (acc: R, x: T) => R, seed?: T | R): Observable { +export function scan(accumulator: (acc: R, value: T) => R, seed?: T | R): Observable { return this.lift(new ScanOperator(accumulator, seed)); } diff --git a/src/operator/single.ts b/src/operator/single.ts index d1299be1ddc..46cb396d6ba 100644 --- a/src/operator/single.ts +++ b/src/operator/single.ts @@ -7,14 +7,12 @@ import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; import {EmptyError} from '../util/EmptyError'; -export function single(predicate?: (value: T, - index: number, - source: Observable) => boolean): Observable { +export function single(predicate?: (value: T, index: number, observable: Observable) => boolean): Observable { return this.lift(new SingleOperator(predicate, this)); } -class SingleOperator implements Operator { - constructor(private predicate?: (value: T, index: number, source: Observable) => boolean, +class SingleOperator implements Operator { + constructor(private predicate?: (value: T, index: number, observable: Observable) => boolean, private source?: Observable) { } @@ -29,12 +27,12 @@ class SingleSubscriber extends Subscriber { private index: number = 0; constructor(destination: Observer, - private predicate?: (value: T, index: number, source: Observable) => boolean, + private predicate?: (value: T, index: number, observable: Observable) => boolean, private source?: Observable) { super(destination); } - private applySingleValue(value): void { + private applySingleValue(value: T): void { if (this.seenValue) { this.destination.error('Sequence contains more than one element'); } else { @@ -49,8 +47,8 @@ class SingleSubscriber extends Subscriber { if (predicate) { let result = tryCatch(predicate)(value, currentIndex, this.source); - if (result === errorObject) { - this.destination.error(result.e); + if (result as any === errorObject) { + this.destination.error(errorObject.e); } else if (result) { this.applySingleValue(value); } diff --git a/src/operator/skip.ts b/src/operator/skip.ts index a6e946d5657..214c1089a10 100644 --- a/src/operator/skip.ts +++ b/src/operator/skip.ts @@ -1,11 +1,12 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; +import {Observable} from '../Observable'; -export function skip(total) { +export function skip(total: number): Observable { return this.lift(new SkipOperator(total)); } -class SkipOperator implements Operator { +class SkipOperator implements Operator { constructor(private total: number) { } @@ -21,7 +22,7 @@ class SkipSubscriber extends Subscriber { super(destination); } - _next(x) { + _next(x: T) { if (++this.count > this.total) { this.destination.next(x); } diff --git a/src/operator/skipUntil.ts b/src/operator/skipUntil.ts index 07cc2104968..a980af8a5ad 100644 --- a/src/operator/skipUntil.ts +++ b/src/operator/skipUntil.ts @@ -6,7 +6,7 @@ export function skipUntil(notifier: Observable): Observable { return this.lift(new SkipUntilOperator(notifier)); } -class SkipUntilOperator implements Operator { +class SkipUntilOperator implements Operator { constructor(private notifier: Observable) { } @@ -66,7 +66,7 @@ class NotificationSubscriber extends Subscriber { this.hasValue = true; } - _error(err) { + _error(err: any) { this.parent.error(err); this.hasValue = true; } diff --git a/src/operator/skipWhile.ts b/src/operator/skipWhile.ts index f0dc49d720a..eeaa4fb9ab1 100644 --- a/src/operator/skipWhile.ts +++ b/src/operator/skipWhile.ts @@ -4,12 +4,12 @@ import {Subscriber} from '../Subscriber'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; -export function skipWhile(predicate: (x: T, index: number) => boolean): Observable { +export function skipWhile(predicate: (value: T, index: number) => boolean): Observable { return this.lift(new SkipWhileOperator(predicate)); } class SkipWhileOperator implements Operator { - constructor(private predicate: (x: T, index: number) => boolean) { + constructor(private predicate: (value: T, index: number) => boolean) { } call(subscriber: Subscriber): Subscriber { @@ -22,7 +22,7 @@ class SkipWhileSubscriber extends Subscriber { private index: number = 0; constructor(destination: Subscriber, - private predicate: (x: T, index: number) => boolean) { + private predicate: (value: T, index: number) => boolean) { super(destination); } @@ -31,8 +31,8 @@ class SkipWhileSubscriber extends Subscriber { if (this.skipping === true) { const index = this.index++; const result = tryCatch(this.predicate)(value, index); - if (result === errorObject) { - destination.error(result.e); + if (result as any === errorObject) { + destination.error(errorObject.e); } else { this.skipping = Boolean(result); } diff --git a/src/operator/startWith.ts b/src/operator/startWith.ts index eefab30ebca..c758a49f8bf 100644 --- a/src/operator/startWith.ts +++ b/src/operator/startWith.ts @@ -6,7 +6,7 @@ import {EmptyObservable} from '../observable/empty'; import {concat} from './concat-static'; import {isScheduler} from '../util/isScheduler'; -export function startWith(...array: (T | Scheduler)[]): Observable { +export function startWith(...array: Array): Observable { let scheduler = array[array.length - 1]; if (isScheduler(scheduler)) { array.pop(); @@ -16,10 +16,10 @@ export function startWith(...array: (T | Scheduler)[]): Observable { const len = array.length; if (len === 1) { - return concat(new ScalarObservable(array[0], scheduler), this); + return concat(new ScalarObservable(array[0], scheduler), this as Observable); } else if (len > 1) { - return concat(new ArrayObservable(array, scheduler), this); + return concat(new ArrayObservable(array, scheduler), this as Observable); } else { - return concat(new EmptyObservable(scheduler), this); + return concat(new EmptyObservable(scheduler), this as Observable); } } diff --git a/src/operator/subscribeOn.ts b/src/operator/subscribeOn.ts index 86bd5b1f40b..98a6248d6a6 100644 --- a/src/operator/subscribeOn.ts +++ b/src/operator/subscribeOn.ts @@ -3,5 +3,5 @@ import {Observable} from '../Observable'; import {SubscribeOnObservable} from '../observable/SubscribeOnObservable'; export function subscribeOn(scheduler: Scheduler, delay: number = 0): Observable { - return new SubscribeOnObservable(this, delay, scheduler); + return new SubscribeOnObservable(this, delay, scheduler); } diff --git a/src/operator/switch.ts b/src/operator/switch.ts index 8abdfff9f66..a8406e4e404 100644 --- a/src/operator/switch.ts +++ b/src/operator/switch.ts @@ -1,11 +1,10 @@ import {Operator} from '../Operator'; -import {Observable} from '../Observable'; import {Subscriber} from '../Subscriber'; import {Subscription} from '../Subscription'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export function _switch(): Observable { +export function _switch(): T { return this.lift(new SwitchOperator()); } diff --git a/src/operator/switchMap.ts b/src/operator/switchMap.ts index bd35613bdc2..116c4dd9487 100644 --- a/src/operator/switchMap.ts +++ b/src/operator/switchMap.ts @@ -7,20 +7,18 @@ import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export function switchMap(project: (value: T, index: number) => Observable, - resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2): Observable { +export function switchMap(project: (value: T, index: number) => Observable | Promise, + resultSelector?: ( + outerValue: T, + innerValue: R, + outerIndex: number, + innerIndex: number) => TResult): Observable { return this.lift(new SwitchMapOperator(project, resultSelector)); } -class SwitchMapOperator implements Operator { - constructor(private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2) { +class SwitchMapOperator implements Operator { + constructor(private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { } call(subscriber: Subscriber): Subscriber { @@ -28,14 +26,14 @@ class SwitchMapOperator implements Operator { } } -class SwitchMapSubscriber extends OuterSubscriber { +class SwitchMapSubscriber extends OuterSubscriber { private innerSubscription: Subscription; private hasCompleted = false; private index: number = 0; constructor(destination: Subscriber, - private project: (value: T, index: number) => Observable, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2) { + private project: (value: T, index: number) => Observable | Promise, + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { super(destination); } @@ -43,8 +41,8 @@ class SwitchMapSubscriber extends OuterSubscriber { const index = this.index++; const destination = this.destination; let result = tryCatch(this.project)(value, index); - if (result === errorObject) { - destination.error(result.e); + if (result as any === errorObject) { + destination.error(errorObject.e); } else { const innerSubscription = this.innerSubscription; if (innerSubscription) { @@ -83,7 +81,7 @@ class SwitchMapSubscriber extends OuterSubscriber { const { resultSelector, destination } = this; if (resultSelector) { const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); } else { destination.next(result); diff --git a/src/operator/switchMapTo.ts b/src/operator/switchMapTo.ts index 9906d1f4b2f..1ea55f0b06d 100644 --- a/src/operator/switchMapTo.ts +++ b/src/operator/switchMapTo.ts @@ -7,20 +7,18 @@ import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -export function switchMapTo(observable: Observable, - projectResult?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2): Observable { - return this.lift(new SwitchMapToOperator(observable, projectResult)); +export function switchMapTo(observable: Observable, + resultSelector?: ( + outerValue: T, + innerValue: R, + outerIndex: number, + innerIndex: number) => TResult): Observable { + return this.lift(new SwitchMapToOperator(observable, resultSelector)); } -class SwitchMapToOperator implements Operator { +class SwitchMapToOperator implements Operator { constructor(private observable: Observable, - private resultSelector?: (outerValue: T, - innerValue: R, - outerIndex: number, - innerIndex: number) => R2) { + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { } call(subscriber: Subscriber): Subscriber { @@ -28,14 +26,14 @@ class SwitchMapToOperator implements Operator { } } -class SwitchMapToSubscriber extends OuterSubscriber { +class SwitchMapToSubscriber extends OuterSubscriber { private innerSubscription: Subscription; private hasCompleted = false; index: number = 0; constructor(destination: Subscriber, private inner: Observable, - private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => R2) { + private resultSelector?: (outerValue: T, innerValue: R, outerIndex: number, innerIndex: number) => TResult) { super(destination); } @@ -77,7 +75,7 @@ class SwitchMapToSubscriber extends OuterSubscriber { const { resultSelector, destination } = this; if (resultSelector) { const result = tryCatch(resultSelector)(outerValue, innerValue, outerIndex, innerIndex); - if (result === errorObject) { + if (result as any === errorObject) { destination.error(errorObject.e); } else { destination.next(result); diff --git a/src/operator/take.ts b/src/operator/take.ts index 403c316e573..e1374d2a651 100644 --- a/src/operator/take.ts +++ b/src/operator/take.ts @@ -2,16 +2,17 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {ArgumentOutOfRangeError} from '../util/ArgumentOutOfRangeError'; import {EmptyObservable} from '../observable/empty'; +import {Observable} from '../Observable'; -export function take(total) { +export function take(total: number): Observable { if (total === 0) { - return new EmptyObservable(); + return new EmptyObservable(); } else { return this.lift(new TakeOperator(total)); } } -class TakeOperator implements Operator { +class TakeOperator implements Operator { constructor(private total: number) { if (this.total < 0) { throw new ArgumentOutOfRangeError; diff --git a/src/operator/takeUntil.ts b/src/operator/takeUntil.ts index a2dcbb5ea39..0b2dcdb9353 100644 --- a/src/operator/takeUntil.ts +++ b/src/operator/takeUntil.ts @@ -3,11 +3,11 @@ import {Observable} from '../Observable'; import {Subscriber} from '../Subscriber'; import {noop} from '../util/noop'; -export function takeUntil(notifier: Observable) { +export function takeUntil(notifier: Observable): Observable { return this.lift(new TakeUntilOperator(notifier)); } -class TakeUntilOperator implements Operator { +class TakeUntilOperator implements Operator { constructor(private notifier: Observable) { } diff --git a/src/operator/takeWhile.ts b/src/operator/takeWhile.ts index 53b40606810..cdebcd81617 100644 --- a/src/operator/takeWhile.ts +++ b/src/operator/takeWhile.ts @@ -8,7 +8,7 @@ export function takeWhile(predicate: (value: T, index: number) => boolean): O return this.lift(new TakeWhileOperator(predicate)); } -class TakeWhileOperator implements Operator { +class TakeWhileOperator implements Operator { constructor(private predicate: (value: T, index: number) => boolean) { } @@ -29,8 +29,8 @@ class TakeWhileSubscriber extends Subscriber { const destination = this.destination; const result = tryCatch(this.predicate)(value, this.index++); - if (result == errorObject) { - destination.error(result.e); + if (result as any == errorObject) { + destination.error(errorObject.e); } else if (Boolean(result)) { destination.next(value); } else { diff --git a/src/operator/throttle.ts b/src/operator/throttle.ts index 494497e1df6..a375777c000 100644 --- a/src/operator/throttle.ts +++ b/src/operator/throttle.ts @@ -8,11 +8,11 @@ import {tryCatch} from '../util/tryCatch'; import {isPromise} from '../util/isPromise'; import {errorObject} from '../util/errorObject'; -export function throttle(durationSelector: (value: T) => Observable | Promise): Observable { +export function throttle(durationSelector: (value: T) => Observable | Promise): Observable { return this.lift(new ThrottleOperator(durationSelector)); } -class ThrottleOperator implements Operator { +class ThrottleOperator implements Operator { constructor(private durationSelector: (value: T) => Observable | Promise) { } @@ -25,7 +25,7 @@ class ThrottleSubscriber extends Subscriber { private throttled: Subscription; constructor(destination: Subscriber, - private durationSelector: (value: T) => Observable | Promise) { + private durationSelector: (value: T) => Observable | Promise) { super(destination); } @@ -33,14 +33,15 @@ class ThrottleSubscriber extends Subscriber { if (!this.throttled) { const destination = this.destination; let duration = tryCatch(this.durationSelector)(value); - if (duration === errorObject) { + if (duration as any === errorObject) { destination.error(errorObject.e); return; } if (isPromise(duration)) { - duration = PromiseObservable.create(duration); + duration = PromiseObservable.create(duration as Promise); } - this.add(this.throttled = duration._subscribe(new ThrottleDurationSelectorSubscriber(this))); + + this.add(this.throttled = (duration as Observable)._subscribe(new ThrottleDurationSelectorSubscriber(this))); destination.next(value); } } @@ -74,7 +75,7 @@ class ThrottleDurationSelectorSubscriber extends Subscriber { this.parent.clearThrottle(); } - _error(err): void { + _error(err: any): void { this.parent.error(err); } diff --git a/src/operator/throttleTime.ts b/src/operator/throttleTime.ts index 27291d728e5..aa9a7f0473e 100644 --- a/src/operator/throttleTime.ts +++ b/src/operator/throttleTime.ts @@ -3,12 +3,13 @@ import {Subscriber} from '../Subscriber'; import {Scheduler} from '../Scheduler'; import {Subscription} from '../Subscription'; import {asap} from '../scheduler/asap'; +import {Observable} from '../Observable'; -export function throttleTime(delay: number, scheduler: Scheduler = asap) { +export function throttleTime(delay: number, scheduler: Scheduler = asap): Observable { return this.lift(new ThrottleTimeOperator(delay, scheduler)); } -class ThrottleTimeOperator implements Operator { +class ThrottleTimeOperator implements Operator { constructor(private delay: number, private scheduler: Scheduler) { } diff --git a/src/operator/timeInterval.ts b/src/operator/timeInterval.ts index 8b09dfe5091..46f75530754 100644 --- a/src/operator/timeInterval.ts +++ b/src/operator/timeInterval.ts @@ -4,36 +4,36 @@ import {Subscriber} from '../Subscriber'; import {Scheduler} from '../Scheduler'; import {queue} from '../scheduler/queue'; -export function timeInterval(scheduler: Scheduler = queue): Observable { +export function timeInterval(scheduler: Scheduler = queue): Observable> { return this.lift(new TimeIntervalOperator(scheduler)); } -export class TimeInterval { - constructor(public value: any, public interval: number) { +export class TimeInterval { + constructor(public value: T, public interval: number) { } }; -class TimeIntervalOperator implements Operator { +class TimeIntervalOperator implements Operator> { constructor(private scheduler: Scheduler) { } - call(observer: Subscriber): Subscriber { + call(observer: Subscriber>): Subscriber { return new TimeIntervalSubscriber(observer, this.scheduler); } } -class TimeIntervalSubscriber extends Subscriber { +class TimeIntervalSubscriber extends Subscriber { private lastTime: number = 0; - constructor(destination: Subscriber, private scheduler: Scheduler) { + constructor(destination: Subscriber>, private scheduler: Scheduler) { super(destination); this.lastTime = scheduler.now(); } - _next(value: TimeInterval) { + _next(value: T) { let now = this.scheduler.now(); let span = now - this.lastTime; this.lastTime = now; diff --git a/src/operator/timeout.ts b/src/operator/timeout.ts index dd7383e10c2..70d81637ee9 100644 --- a/src/operator/timeout.ts +++ b/src/operator/timeout.ts @@ -3,24 +3,25 @@ import {Subscriber} from '../Subscriber'; import {Scheduler} from '../Scheduler'; import {queue} from '../scheduler/queue'; import {isDate} from '../util/isDate'; +import {Observable} from '../Observable'; -export function timeout(due: number|Date, - errorToSend: any = null, - scheduler: Scheduler = queue) { +export function timeout(due: number | Date, + errorToSend: any = null, + scheduler: Scheduler = queue): Observable { let absoluteTimeout = isDate(due); let waitFor = absoluteTimeout ? (+due - scheduler.now()) : due; return this.lift(new TimeoutOperator(waitFor, absoluteTimeout, errorToSend, scheduler)); } -class TimeoutOperator implements Operator { +class TimeoutOperator implements Operator { constructor(private waitFor: number, private absoluteTimeout: boolean, private errorToSend: any, private scheduler: Scheduler) { } - call(subscriber: Subscriber) { - return new TimeoutSubscriber( + call(subscriber: Subscriber) { + return new TimeoutSubscriber( subscriber, this.absoluteTimeout, this.waitFor, this.errorToSend, this.scheduler ); } @@ -69,7 +70,7 @@ class TimeoutSubscriber extends Subscriber { } } - _error(err) { + _error(err: any) { this.destination.error(err); this._hasCompleted = true; } diff --git a/src/operator/timeoutWith.ts b/src/operator/timeoutWith.ts index 09ff5253c4f..66bf947a13a 100644 --- a/src/operator/timeoutWith.ts +++ b/src/operator/timeoutWith.ts @@ -10,20 +10,20 @@ import {subscribeToResult} from '../util/subscribeToResult'; export function timeoutWith(due: number | Date, withObservable: Observable, - scheduler: Scheduler = queue): Observable | Observable { + scheduler: Scheduler = queue): Observable { let absoluteTimeout = isDate(due); let waitFor = absoluteTimeout ? (+due - scheduler.now()) : due; return this.lift(new TimeoutWithOperator(waitFor, absoluteTimeout, withObservable, scheduler)); } -class TimeoutWithOperator implements Operator { +class TimeoutWithOperator implements Operator { constructor(private waitFor: number, private absoluteTimeout: boolean, private withObservable: Observable, private scheduler: Scheduler) { } - call(subscriber: Subscriber) { + call(subscriber: Subscriber) { return new TimeoutWithSubscriber( subscriber, this.absoluteTimeout, this.waitFor, this.withObservable, this.scheduler ); @@ -75,7 +75,7 @@ class TimeoutWithSubscriber extends OuterSubscriber { } } - _error(err) { + _error(err: any) { this.destination.error(err); this._hasCompleted = true; } diff --git a/src/operator/toArray.ts b/src/operator/toArray.ts index f1432bf937e..d2aec1b8b42 100644 --- a/src/operator/toArray.ts +++ b/src/operator/toArray.ts @@ -1,25 +1,26 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; +import {Observable} from '../Observable'; -export function toArray() { +export function toArray(): Observable { return this.lift(new ToArrayOperator()); } -class ToArrayOperator implements Operator { +class ToArrayOperator implements Operator { call(subscriber: Subscriber): Subscriber { - return new ToArraySubscriber(subscriber); + return new ToArraySubscriber(subscriber); } } class ToArraySubscriber extends Subscriber { - array: T [] = []; + array: T[] = []; constructor(destination: Subscriber) { super(destination); } - _next(x) { + _next(x: T) { this.array.push(x); } diff --git a/src/operator/toPromise.ts b/src/operator/toPromise.ts index cc7f92e0c95..dd8c4dc60f5 100644 --- a/src/operator/toPromise.ts +++ b/src/operator/toPromise.ts @@ -15,6 +15,6 @@ export function toPromise(PromiseCtor?: PromiseConstructor): Promise { return new PromiseCtor((resolve, reject) => { let value: any; - this.subscribe(x => value = x, err => reject(err), () => resolve(value)); + this.subscribe((x: T) => value = x, (err: any) => reject(err), () => resolve(value)); }); } diff --git a/src/operator/window.ts b/src/operator/window.ts index cc152c07199..2e92e2c9b49 100644 --- a/src/operator/window.ts +++ b/src/operator/window.ts @@ -7,7 +7,7 @@ export function window(closingNotifier: Observable): Observable implements Operator { +class WindowOperator implements Operator> { constructor(private closingNotifier: Observable) { } @@ -53,7 +53,7 @@ class WindowSubscriber extends Subscriber { } } -class WindowClosingNotifierSubscriber extends Subscriber { +class WindowClosingNotifierSubscriber extends Subscriber { constructor(private parent: WindowSubscriber) { super(null); } diff --git a/src/operator/windowCount.ts b/src/operator/windowCount.ts index 199565d74e9..8f732873e28 100644 --- a/src/operator/windowCount.ts +++ b/src/operator/windowCount.ts @@ -8,7 +8,7 @@ export function windowCount(windowSize: number, return this.lift(new WindowCountOperator(windowSize, startWindowEvery)); } -class WindowCountOperator implements Operator { +class WindowCountOperator implements Operator> { constructor(private windowSize: number, private startWindowEvery: number) { diff --git a/src/operator/windowTime.ts b/src/operator/windowTime.ts index d398dd0e885..18f35550241 100644 --- a/src/operator/windowTime.ts +++ b/src/operator/windowTime.ts @@ -12,7 +12,7 @@ export function windowTime(windowTimeSpan: number, return this.lift(new WindowTimeOperator(windowTimeSpan, windowCreationInterval, scheduler)); } -class WindowTimeOperator implements Operator { +class WindowTimeOperator implements Operator> { constructor(private windowTimeSpan: number, private windowCreationInterval: number, @@ -36,7 +36,7 @@ class WindowTimeSubscriber extends Subscriber { super(destination); if (windowCreationInterval !== null && windowCreationInterval >= 0) { let window = this.openWindow(); - const closeState = { subscriber: this, window, context: null }; + const closeState = { subscriber: this, window, context: null }; const creationState = { windowTimeSpan, windowCreationInterval, subscriber: this, scheduler }; this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState)); this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState)); @@ -55,7 +55,7 @@ class WindowTimeSubscriber extends Subscriber { } } - _error(err) { + _error(err: any) { const windows = this.windows; while (windows.length > 0) { windows.shift().error(err); @@ -102,11 +102,11 @@ function dispatchWindowTimeSpanOnly(state: TimeSpanOnlyState) { (this).schedule(state, windowTimeSpan); } -function dispatchWindowCreation(state) { +function dispatchWindowCreation(state: any) { let { windowTimeSpan, subscriber, scheduler, windowCreationInterval } = state; let window = subscriber.openWindow(); let action = this; - let context = { action, subscription: null }; + let context = { action, subscription: null }; const timeSpanState = { subscriber, window, context }; context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState); action.add(context.subscription); diff --git a/src/operator/windowToggle.ts b/src/operator/windowToggle.ts index 866e68eb7ca..15633775338 100644 --- a/src/operator/windowToggle.ts +++ b/src/operator/windowToggle.ts @@ -9,17 +9,17 @@ import {errorObject} from '../util/errorObject'; export function windowToggle(openings: Observable, closingSelector: (openValue: O) => Observable): Observable> { - return this.lift(new WindowToggleOperator(openings, closingSelector)); + return this.lift(new WindowToggleOperator(openings, closingSelector)); } -class WindowToggleOperator implements Operator { +class WindowToggleOperator implements Operator> { constructor(private openings: Observable, private closingSelector: (openValue: O) => Observable) { } call(subscriber: Subscriber>): Subscriber { - return new WindowToggleSubscriber( + return new WindowToggleSubscriber( subscriber, this.openings, this.closingSelector ); } @@ -69,15 +69,15 @@ class WindowToggleSubscriber extends Subscriber { openWindow(value: O) { const closingSelector = this.closingSelector; let closingNotifier = tryCatch(closingSelector)(value); - if (closingNotifier === errorObject) { - this.error(closingNotifier.e); + if (closingNotifier as any === errorObject) { + this.error(errorObject.e); } else { const destination = this.destination; const window = new Subject(); - const subscription = new Subscription(); + const subscription = new Subscription(); const context = { window, subscription }; this.contexts.push(context); - const subscriber = new WindowClosingNotifierSubscriber(this, context); + const subscriber = new WindowClosingNotifierSubscriber(this, context); const closingSubscription = closingNotifier._subscribe(subscriber); subscription.add(closingSubscription); destination.add(subscription); @@ -109,7 +109,7 @@ class WindowClosingNotifierSubscriber extends Subscriber { this.parent.closeWindow(this.windowContext); } - _error(err) { + _error(err: any) { this.parent.error(err); } @@ -127,7 +127,7 @@ class WindowToggleOpeningsSubscriber extends Subscriber { this.parent.openWindow(value); } - _error(err) { + _error(err: any) { this.parent.error(err); } diff --git a/src/operator/windowWhen.ts b/src/operator/windowWhen.ts index df70d01b915..330af6d4356 100644 --- a/src/operator/windowWhen.ts +++ b/src/operator/windowWhen.ts @@ -11,7 +11,7 @@ export function windowWhen(closingSelector: () => Observable): Observabl return this.lift(new WindowOperator(closingSelector)); } -class WindowOperator implements Operator { +class WindowOperator implements Operator> { constructor(private closingSelector: () => Observable) { } @@ -75,8 +75,8 @@ class WindowSubscriber extends Subscriber { this.destination.next(window); const closingNotifier = tryCatch(this.closingSelector)(); - if (closingNotifier === errorObject) { - const err = closingNotifier.e; + if (closingNotifier as any === errorObject) { + const err = errorObject.e; this.destination.error(err); this.window.error(err); } else { @@ -88,7 +88,7 @@ class WindowSubscriber extends Subscriber { } } -class WindowClosingNotifierSubscriber extends Subscriber { +class WindowClosingNotifierSubscriber extends Subscriber { constructor(private parent: WindowSubscriber) { super(null); } @@ -97,7 +97,7 @@ class WindowClosingNotifierSubscriber extends Subscriber { this.parent.openWindow(); } - _error(err) { + _error(err: any) { this.parent.error(err); } diff --git a/src/operator/withLatestFrom.ts b/src/operator/withLatestFrom.ts index cd463a64cb1..1be3f92a98c 100644 --- a/src/operator/withLatestFrom.ts +++ b/src/operator/withLatestFrom.ts @@ -24,8 +24,8 @@ import {subscribeToResult} from '../util/subscribeToResult'; * result: ---([a,d,x])---------([b,e,y])--------([c,f,z])---| * ``` */ -export function withLatestFrom(...args: Array | ((...values: Array) => R)>): Observable { - let project; +export function withLatestFrom(...args: Array | ((...values: Array) => R)>): Observable { + let project: any; if (typeof args[args.length - 1] === 'function') { project = args.pop(); } @@ -39,7 +39,7 @@ class WithLatestFromOperator implements Operator { } call(subscriber: Subscriber): Subscriber { - return new WithLatestFromSubscriber(subscriber, this.observables, this.project); + return new WithLatestFromSubscriber(subscriber, this.observables, this.project); } } @@ -64,7 +64,7 @@ class WithLatestFromSubscriber extends OuterSubscriber { } } - notifyNext(observable, value, observableIndex, index) { + notifyNext(observable: any, value: any, observableIndex: number, index: number) { this.values[observableIndex] = value; const toRespond = this.toRespond; if (toRespond.length > 0) { diff --git a/src/operator/zip-static.ts b/src/operator/zip-static.ts index 24c8c2a4f8f..55b0393ae48 100644 --- a/src/operator/zip-static.ts +++ b/src/operator/zip-static.ts @@ -7,5 +7,5 @@ export function zip(...observables: Array | ((...values: A if (typeof project === 'function') { observables.pop(); } - return new ArrayObservable(observables).lift(new ZipOperator(project)); + return new ArrayObservable(observables).lift(new ZipOperator(project)); } diff --git a/src/operator/zip-support.ts b/src/operator/zip-support.ts index 5750c58fe76..4dee7954a6d 100644 --- a/src/operator/zip-support.ts +++ b/src/operator/zip-support.ts @@ -19,7 +19,7 @@ export class ZipOperator implements Operator { } call(subscriber: Subscriber): Subscriber { - return new ZipSubscriber(subscriber, this.project); + return new ZipSubscriber(subscriber, this.project); } } @@ -27,7 +27,7 @@ export class ZipSubscriber extends Subscriber { private index = 0; private values: any; private project: (...values: Array) => R; - private iterators = []; + private iterators: LookAheadIterator[] = []; private active = 0; constructor(destination: Subscriber, @@ -38,7 +38,7 @@ export class ZipSubscriber extends Subscriber { this.values = values; } - _next(value) { + _next(value: any) { const iterators = this.iterators; const index = this.index++; if (isArray(value)) { @@ -56,8 +56,8 @@ export class ZipSubscriber extends Subscriber { this.active = len; for (let i = 0; i < len; i++) { let iterator = iterators[i]; - if (iterator.stillUnsubscribed) { - iterator.subscribe(iterator, i); + if ((iterator as any).stillUnsubscribed) { + (iterator as any).subscribe(iterator, i); } else { this.active--; // not an observable } @@ -85,7 +85,7 @@ export class ZipSubscriber extends Subscriber { } let shouldComplete = false; - const args = []; + const args: any[] = []; for (let i = 0; i < len; i++) { let iterator = iterators[i]; let result = iterator.next(); @@ -221,7 +221,7 @@ class ZipBufferIterator extends OuterSubscriber implements LookAhead } } - notifyNext(outerValue, innerValue, outerIndex, innerIndex) { + notifyNext(outerValue: any, innerValue: any, outerIndex: any, innerIndex: any) { this.buffer.push(innerValue); this.parent.checkIterators(); } @@ -229,4 +229,4 @@ class ZipBufferIterator extends OuterSubscriber implements LookAhead subscribe(value: any, index: number) { this.add(subscribeToResult(this, this.observable, this, index)); } -} \ No newline at end of file +} diff --git a/src/operator/zip.ts b/src/operator/zip.ts index 4bdc496245a..233f768e5c8 100644 --- a/src/operator/zip.ts +++ b/src/operator/zip.ts @@ -1,7 +1,7 @@ import {Observable} from '../Observable'; import {zip} from './zip-static'; -export function zipProto(...observables: Array | ((...values: Array) => R)>): Observable { +export function zip(...observables: Array | ((...values: Array) => R)>): Observable { observables.unshift(this); return zip.apply(this, observables); } diff --git a/src/operator/zipAll.ts b/src/operator/zipAll.ts index bd9fb668828..2f8300117a9 100644 --- a/src/operator/zipAll.ts +++ b/src/operator/zipAll.ts @@ -1,5 +1,6 @@ import {ZipOperator} from './zip-support'; +import {Observable} from '../Observable'; -export function zipAll(project?: (...values: Array) => R) { +export function zipAll(project?: (...values: Array) => R): Observable { return this.lift(new ZipOperator(project)); } diff --git a/src/scheduler/Action.ts b/src/scheduler/Action.ts index 8a041edc8fb..3822ea9a1a5 100644 --- a/src/scheduler/Action.ts +++ b/src/scheduler/Action.ts @@ -5,7 +5,7 @@ export interface Action extends Subscription { work: (state?: any) => void|Subscription; state?: any; delay?: number; - schedule(state?: any, delay?: number); + schedule(state?: any, delay?: number): void; execute(): void; scheduler: Scheduler; -} \ No newline at end of file +} diff --git a/src/scheduler/QueueScheduler.ts b/src/scheduler/QueueScheduler.ts index 721cdd7d7f5..578f4369b37 100644 --- a/src/scheduler/QueueScheduler.ts +++ b/src/scheduler/QueueScheduler.ts @@ -19,7 +19,7 @@ export class QueueScheduler implements Scheduler { } this.active = true; const actions = this.actions; - for (let action; action = actions.shift(); ) { + for (let action: QueueAction; action = actions.shift(); ) { action.execute(); } this.active = false; @@ -38,4 +38,4 @@ export class QueueScheduler implements Scheduler { scheduleLater(work: (x?: any) => Subscription | void, delay: number, state?: any): Action { return new FutureAction(this, work).schedule(state, delay); } -} \ No newline at end of file +} diff --git a/src/scheduler/VirtualTimeScheduler.ts b/src/scheduler/VirtualTimeScheduler.ts index 13a6e3328de..2d720d3ae2e 100644 --- a/src/scheduler/VirtualTimeScheduler.ts +++ b/src/scheduler/VirtualTimeScheduler.ts @@ -77,7 +77,7 @@ class VirtualAction extends Subscription implements Action { return this; } const scheduler = this.scheduler; - let action; + let action: Action; if (this.calls++ === 0) { // the action is not being rescheduled. action = this; @@ -114,4 +114,4 @@ class VirtualAction extends Subscription implements Action { super.unsubscribe(); } -} \ No newline at end of file +} diff --git a/src/subject/ReplaySubject.ts b/src/subject/ReplaySubject.ts index 8dcca19fff8..1d1371adc5d 100644 --- a/src/subject/ReplaySubject.ts +++ b/src/subject/ReplaySubject.ts @@ -40,7 +40,7 @@ export class ReplaySubject extends Subject { return (this.scheduler || queue).now(); } - private _trimBufferThenGetEvents(now): ReplayEvent[] { + private _trimBufferThenGetEvents(now: number): ReplayEvent[] { const bufferSize = this.bufferSize; const _windowTime = this._windowTime; const events = this.events; @@ -74,4 +74,3 @@ class ReplayEvent { constructor(public time: number, public value: T) { } } - diff --git a/src/testing/ColdObservable.ts b/src/testing/ColdObservable.ts index 58c1c1ee4d2..7920a319301 100644 --- a/src/testing/ColdObservable.ts +++ b/src/testing/ColdObservable.ts @@ -5,6 +5,7 @@ import {TestMessage} from './TestMessage'; import {SubscriptionLog} from './SubscriptionLog'; import {SubscriptionLoggable} from './SubscriptionLoggable'; import {applyMixins} from '../util/applyMixins'; +import {Subscriber} from '../Subscriber'; export class ColdObservable extends Observable implements SubscriptionLoggable { public subscriptions: SubscriptionLog[] = []; @@ -14,7 +15,7 @@ export class ColdObservable extends Observable implements SubscriptionLogg constructor(public messages: TestMessage[], scheduler: Scheduler) { - super(function (subscriber) { + super(function (subscriber: Subscriber) { const observable: ColdObservable = this; const index = observable.logSubscribedFrame(); subscriber.add(new Subscription(() => { @@ -26,7 +27,7 @@ export class ColdObservable extends Observable implements SubscriptionLogg this.scheduler = scheduler; } - scheduleMessages(subscriber) { + scheduleMessages(subscriber: Subscriber) { const messagesLength = this.messages.length; for (let i = 0; i < messagesLength; i++) { const message = this.messages[i]; diff --git a/src/testing/TestScheduler.ts b/src/testing/TestScheduler.ts index 542467424d2..c052fa426e4 100644 --- a/src/testing/TestScheduler.ts +++ b/src/testing/TestScheduler.ts @@ -6,6 +6,7 @@ import {ColdObservable} from './ColdObservable'; import {HotObservable} from './HotObservable'; import {TestMessage} from './TestMessage'; import {SubscriptionLog} from './SubscriptionLog'; +import {Subscription} from '../Subscription'; interface FlushableTest { ready: boolean; @@ -41,7 +42,7 @@ export class TestScheduler extends VirtualTimeScheduler { throw new Error('Cold observable cannot have unsubscription marker "!"'); } const messages = TestScheduler.parseMarbles(marbles, values, error); - const cold = new ColdObservable(messages, this); + const cold = new ColdObservable(messages, this); this.coldObservables.push(cold); return cold; } @@ -51,7 +52,7 @@ export class TestScheduler extends VirtualTimeScheduler { throw new Error('Hot observable cannot have unsubscription marker "!"'); } const messages = TestScheduler.parseMarbles(marbles, values, error); - const subject = new HotObservable(messages, this); + const subject = new HotObservable(messages, this); this.hotObservables.push(subject); return subject; } @@ -75,7 +76,7 @@ export class TestScheduler extends VirtualTimeScheduler { const flushTest: FlushableTest = { actual, ready: false }; const unsubscriptionFrame = TestScheduler .parseMarblesAsSubscriptions(unsubscriptionMarbles).unsubscribedFrame; - let subscription; + let subscription: Subscription; this.schedule(() => { subscription = observable.subscribe(x => { @@ -196,8 +197,8 @@ export class TestScheduler extends VirtualTimeScheduler { const subIndex = marbles.indexOf('^'); const frameOffset = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor); const getValue = typeof values !== 'object' ? - (x) => x : - (x) => { + (x: any) => x : + (x: any) => { // Support Observable-of-Observables if (materializeInnerObservables && values[x] instanceof ColdObservable) { return values[x].messages; @@ -208,7 +209,7 @@ export class TestScheduler extends VirtualTimeScheduler { for (let i = 0; i < len; i++) { const frame = i * this.frameTimeFactor + frameOffset; - let notification; + let notification: Notification; const c = marbles[i]; switch (c) { case '-': @@ -239,4 +240,4 @@ export class TestScheduler extends VirtualTimeScheduler { } return testMessages; } -} \ No newline at end of file +} diff --git a/src/util/Immediate.ts b/src/util/Immediate.ts index aacb6bcdc96..2606df17db2 100644 --- a/src/util/Immediate.ts +++ b/src/util/Immediate.ts @@ -46,7 +46,7 @@ export class ImmediateDefinition { this.setImmediate = this.createSetTimeoutSetImmediate(); } - let ci = function clearImmediate(handle) { + let ci = function clearImmediate(handle: any) { delete (clearImmediate).instance.tasksByHandle[handle]; }; @@ -89,7 +89,7 @@ export class ImmediateDefinition { // This function accepts the same arguments as setImmediate, but // returns a function that requires no arguments. - partiallyApplied(handler, ...args) { + partiallyApplied(handler: any, ...args: any[]) { let fn = function result () { const { handler, args } = result; if (typeof handler === 'function') { @@ -105,7 +105,7 @@ export class ImmediateDefinition { return fn; } - addFromSetImmediateArguments(args) { + addFromSetImmediateArguments(args: any[]) { this.tasksByHandle[this.nextHandle] = this.partiallyApplied.apply(undefined, args); return this.nextHandle++; } @@ -130,7 +130,7 @@ export class ImmediateDefinition { const root = this.root; let messagePrefix = 'setImmediate$' + root.Math.random() + '$'; - let onGlobalMessage = function globalMessageHandler(event) { + let onGlobalMessage = function globalMessageHandler(event: any) { const instance = (globalMessageHandler).instance; if (event.source === root && typeof event.data === 'string' && @@ -155,7 +155,7 @@ export class ImmediateDefinition { return fn; } - runIfPresent(handle) { + runIfPresent(handle: any) { // From the spec: 'Wait until any invocations of this algorithm started before this one have completed.' // So if we're currently running a task, we'll need to delay this invocation. if (this.currentlyRunningATask) { @@ -178,7 +178,7 @@ export class ImmediateDefinition { createMessageChannelSetImmediate() { let channel = new this.root.MessageChannel(); - channel.port1.onmessage = (event) => { + channel.port1.onmessage = (event: any) => { let handle = event.data; this.runIfPresent(handle); }; @@ -235,4 +235,4 @@ export class ImmediateDefinition { return fn; } } -export const Immediate = new ImmediateDefinition(root); \ No newline at end of file +export const Immediate = new ImmediateDefinition(root); diff --git a/src/util/MapPolyfill.ts b/src/util/MapPolyfill.ts index 98aeed1eaed..ad599a3465f 100644 --- a/src/util/MapPolyfill.ts +++ b/src/util/MapPolyfill.ts @@ -1,14 +1,14 @@ export class MapPolyfill { public size = 0; - private _values = []; - private _keys = []; + private _values: any[] = []; + private _keys: any[] = []; - get(key): any { + get(key: any) { const i = this._keys.indexOf(key); return i === -1 ? undefined : this._values[i]; } - set(key, value): any { + set(key: any, value: any) { const i = this._keys.indexOf(key); if (i === -1) { this._keys.push(key); @@ -20,7 +20,7 @@ export class MapPolyfill { return this; } - delete(key): boolean { + delete(key: any) { const i = this._keys.indexOf(key); if (i === -1) { return false; } this._values.splice(i, 1); @@ -29,9 +29,9 @@ export class MapPolyfill { return true; } - forEach(cb, thisArg): void { + forEach(cb: any, thisArg: any) { for (let i = 0; i < this.size; i++) { cb.call(thisArg, this._values[i], this._keys[i]); } } -} \ No newline at end of file +} diff --git a/src/util/SymbolShim.ts b/src/util/SymbolShim.ts index eebbf45fda1..c2442f76741 100644 --- a/src/util/SymbolShim.ts +++ b/src/util/SymbolShim.ts @@ -1,6 +1,6 @@ import {root} from './root'; -export function polyfillSymbol(root) { +export function polyfillSymbol(root: any) { const Symbol = ensureSymbol(root); ensureIterator(Symbol, root); ensureObservable(Symbol); @@ -8,7 +8,7 @@ export function polyfillSymbol(root) { return Symbol; } -export function ensureFor(Symbol) { +export function ensureFor(Symbol: any) { if (!Symbol.for) { Symbol.for = symbolForPolyfill; } @@ -16,20 +16,20 @@ export function ensureFor(Symbol) { let id = 0; -export function ensureSymbol(root) { +export function ensureSymbol(root: any) { if (!root.Symbol) { - root.Symbol = function symbolFuncPolyfill(description) { + root.Symbol = function symbolFuncPolyfill(description: any) { return `@@Symbol(${description}):${id++}`; }; } return root.Symbol; } -export function symbolForPolyfill(key) { +export function symbolForPolyfill(key: any) { return '@@' + key; } -export function ensureIterator(Symbol, root) { +export function ensureIterator(Symbol: any, root: any) { if (!Symbol.iterator) { if (typeof Symbol.for === 'function') { Symbol.iterator = Symbol.for('iterator'); @@ -52,7 +52,7 @@ export function ensureIterator(Symbol, root) { } } -export function ensureObservable(Symbol) { +export function ensureObservable(Symbol: any) { if (!Symbol.observable) { if (typeof Symbol.for === 'function') { Symbol.observable = Symbol.for('observable'); @@ -62,4 +62,4 @@ export function ensureObservable(Symbol) { } } -export const SymbolShim = polyfillSymbol(root); \ No newline at end of file +export const SymbolShim = polyfillSymbol(root); diff --git a/src/util/isArray.ts b/src/util/isArray.ts index ebf5d017026..a6bb48acf7f 100644 --- a/src/util/isArray.ts +++ b/src/util/isArray.ts @@ -1 +1 @@ -export const isArray = Array.isArray || (x => x && typeof x.length === 'number'); \ No newline at end of file +export const isArray = Array.isArray || ((x: any): x is T[] => x && typeof x.length === 'number'); diff --git a/src/util/isDate.ts b/src/util/isDate.ts index d56736d6c9f..b18edf071ad 100644 --- a/src/util/isDate.ts +++ b/src/util/isDate.ts @@ -1,3 +1,3 @@ -export function isDate(value) { +export function isDate(value: any): value is Date { return value instanceof Date && !isNaN(+value); -} \ No newline at end of file +} diff --git a/src/util/isNumeric.ts b/src/util/isNumeric.ts index a140f2af2ad..3b393c3e50e 100644 --- a/src/util/isNumeric.ts +++ b/src/util/isNumeric.ts @@ -1,9 +1,9 @@ const is_array = Array.isArray; -export function isNumeric(val) { +export function isNumeric(val: any): val is number { // parseFloat NaNs numeric-cast false positives (null|true|false|"") // ...but misinterprets leading-number strings, particularly hex literals ("0x...") // subtraction forces infinities to NaN // adding 1 corrects loss of precision from parseFloat (#15100) return !is_array(val) && (val - parseFloat(val) + 1) >= 0; -}; \ No newline at end of file +}; diff --git a/src/util/isPromise.ts b/src/util/isPromise.ts index 97d592b649a..5df1f9b22bc 100644 --- a/src/util/isPromise.ts +++ b/src/util/isPromise.ts @@ -1,3 +1,3 @@ -export function isPromise(value: any): boolean { - return value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; -} \ No newline at end of file +export function isPromise(value: any | Promise): value is Promise { + return value && typeof (value as any).subscribe !== 'function' && typeof (value as any).then === 'function'; +} diff --git a/src/util/isScheduler.ts b/src/util/isScheduler.ts index d1003f25549..1d7b0f5a1dc 100644 --- a/src/util/isScheduler.ts +++ b/src/util/isScheduler.ts @@ -1,3 +1,4 @@ -export function isScheduler(value: any): boolean { - return value && typeof value.schedule === 'function'; -} \ No newline at end of file +import {Scheduler} from '../Scheduler'; +export function isScheduler(value: any): value is Scheduler { + return value && typeof (value as any).schedule === 'function'; +} diff --git a/src/util/subscribeToResult.ts b/src/util/subscribeToResult.ts index 690d5140267..fd9e1e258be 100644 --- a/src/util/subscribeToResult.ts +++ b/src/util/subscribeToResult.ts @@ -35,13 +35,13 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, destination.complete(); } } else if (typeof result.then === 'function') { - result.then(x => { + result.then((x: any) => { if (!destination.isUnsubscribed) { destination.next(x); destination.complete(); } - }, err => destination.error(err)) - .then(null, err => { + }, (err: any) => destination.error(err)) + .then(null, (err: any) => { // Escaping the Promise trap: globally throw unhandled errors setTimeout(() => { throw err; }); }); @@ -66,4 +66,4 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, } else { destination.error(new TypeError('unknown type returned')); } -} \ No newline at end of file +} diff --git a/src/util/throwError.ts b/src/util/throwError.ts index c9274cad900..51326e89383 100644 --- a/src/util/throwError.ts +++ b/src/util/throwError.ts @@ -1 +1 @@ -export function throwError(e) { throw e; } +export function throwError(e: any) { throw e; } diff --git a/src/util/tryCatch.ts b/src/util/tryCatch.ts index 1a68fef7069..dca662f6cd8 100644 --- a/src/util/tryCatch.ts +++ b/src/util/tryCatch.ts @@ -11,7 +11,7 @@ function tryCatcher(): any { } } -export function tryCatch(fn: Function): Function { +export function tryCatch(fn: T): T { tryCatchTarget = fn; - return tryCatcher; -}; \ No newline at end of file + return tryCatcher; +}; diff --git a/tsconfig.json b/tsconfig.json index 9c90f016a65..74ca85b399f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "preserveConstEnums": true, "sourceMap": true, "declaration": true, + "noImplicitAny": true, "target": "es6", "outDir": "dist/es6" },