From 94156a214f905555b6e57bc3f7cf965629028406 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 7 Feb 2018 19:34:56 -0800 Subject: [PATCH] refactor(types): enable strict fntype compiler option (#3050) --- .../observable/BoundCallbackObservable.ts | 13 +++++---- .../observable/BoundNodeCallbackObservable.ts | 2 +- .../observable/SubscribeOnObservable.ts | 4 +-- src/internal/observable/dom/AjaxObservable.ts | 2 +- src/internal/observable/pairs.ts | 4 ++- src/internal/observable/race.ts | 2 +- src/internal/operators/bufferTime.ts | 28 +++++++++---------- src/internal/operators/concatMapTo.ts | 2 +- src/internal/operators/expand.ts | 2 +- src/internal/operators/groupBy.ts | 10 +++---- src/internal/operators/mergeMapTo.ts | 2 +- src/internal/operators/refCount.ts | 2 +- src/internal/operators/startWith.ts | 2 +- src/internal/operators/subscribeOn.ts | 2 +- src/internal/operators/switchMapTo.ts | 6 ++-- src/internal/operators/throttleTime.ts | 2 +- src/internal/operators/timeout.ts | 2 +- src/internal/operators/timeoutWith.ts | 2 +- src/internal/operators/windowTime.ts | 8 +++--- src/internal/operators/windowToggle.ts | 4 +-- .../patching/operator/combineLatest.ts | 2 +- src/internal/patching/operator/concatMapTo.ts | 2 +- src/internal/patching/operator/mergeMapTo.ts | 2 +- src/internal/patching/operator/publishLast.ts | 2 +- src/internal/patching/operator/scan.ts | 6 ++-- src/internal/patching/operator/switchMapTo.ts | 2 +- .../scheduler/AnimationFrameAction.ts | 3 +- src/internal/scheduler/AsapAction.ts | 3 +- src/internal/scheduler/AsyncAction.ts | 2 +- src/internal/scheduler/QueueAction.ts | 3 +- .../scheduler/VirtualTimeScheduler.ts | 7 +++-- src/internal/testing/ColdObservable.ts | 8 +++--- src/internal/util/pipe.ts | 2 +- tsconfig.json | 1 + 34 files changed, 78 insertions(+), 68 deletions(-) diff --git a/src/internal/observable/BoundCallbackObservable.ts b/src/internal/observable/BoundCallbackObservable.ts index 45cd962043..fbfed95fc7 100644 --- a/src/internal/observable/BoundCallbackObservable.ts +++ b/src/internal/observable/BoundCallbackObservable.ts @@ -172,7 +172,7 @@ export class BoundCallbackObservable extends Observable { static create(func: Function, selector: Function | void = undefined, scheduler?: IScheduler): (...args: any[]) => Observable { - return function(this: any, ...args: any[]): Observable { + return function (this: any, ...args: any[]): Observable { return new BoundCallbackObservable(func, selector, args, this, scheduler); }; } @@ -201,7 +201,7 @@ export class BoundCallbackObservable extends Observable { const result = tryCatch(selector).apply(this, innerArgs); if (result === errorObject) { subject.error(errorObject.e); - } else { + } else { subject.next(result); subject.complete(); } @@ -220,7 +220,8 @@ export class BoundCallbackObservable extends Observable { } return subject.subscribe(subscriber); } else { - return scheduler.schedule(BoundCallbackObservable.dispatch, 0, { source: this, subscriber, context: this.context }); + return scheduler.schedule<{ source: BoundCallbackObservable, subscriber: Subscriber, context: any }> + (BoundCallbackObservable.dispatch, 0, { source: this, subscriber, context: this.context }); } } @@ -239,13 +240,13 @@ export class BoundCallbackObservable extends Observable { if (selector) { const result = tryCatch(selector).apply(this, innerArgs); if (result === errorObject) { - self.add(scheduler.schedule(dispatchError, 0, { err: errorObject.e, subject })); + self.add(scheduler.schedule>(dispatchError, 0, { err: errorObject.e, subject })); } else { - self.add(scheduler.schedule(dispatchNext, 0, { value: result, subject })); + self.add(scheduler.schedule>(dispatchNext, 0, { value: result, subject })); } } else { const value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs; - self.add(scheduler.schedule(dispatchNext, 0, { value, subject })); + self.add(scheduler.schedule>(dispatchNext, 0, { value, subject })); } }; // use named function to pass values in without closure diff --git a/src/internal/observable/BoundNodeCallbackObservable.ts b/src/internal/observable/BoundNodeCallbackObservable.ts index 1d76887762..a6b683fbf8 100644 --- a/src/internal/observable/BoundNodeCallbackObservable.ts +++ b/src/internal/observable/BoundNodeCallbackObservable.ts @@ -207,7 +207,7 @@ export class BoundNodeCallbackObservable extends Observable { } return subject.subscribe(subscriber); } else { - return scheduler.schedule(dispatch, 0, { source: this, subscriber, context: this.context }); + return scheduler.schedule>(dispatch, 0, { source: this, subscriber, context: this.context }); } } } diff --git a/src/internal/observable/SubscribeOnObservable.ts b/src/internal/observable/SubscribeOnObservable.ts index 61b80f2bf8..35be9dfc10 100644 --- a/src/internal/observable/SubscribeOnObservable.ts +++ b/src/internal/observable/SubscribeOnObservable.ts @@ -43,8 +43,8 @@ export class SubscribeOnObservable extends Observable { const source = this.source; const scheduler = this.scheduler; - return scheduler.schedule(SubscribeOnObservable.dispatch, delay, { + return scheduler.schedule>(SubscribeOnObservable.dispatch, delay, { source, subscriber }); } -} +} \ No newline at end of file diff --git a/src/internal/observable/dom/AjaxObservable.ts b/src/internal/observable/dom/AjaxObservable.ts index 0bde0a3eb1..f8c3627998 100644 --- a/src/internal/observable/dom/AjaxObservable.ts +++ b/src/internal/observable/dom/AjaxObservable.ts @@ -350,7 +350,7 @@ export class AjaxSubscriber extends Subscriber { (xhrError).progressSubscriber = progressSubscriber; } - function xhrReadyStateChange(this: XMLHttpRequest, e: ProgressEvent) { + function xhrReadyStateChange(this: XMLHttpRequest, e: Event) { const { subscriber, progressSubscriber, request } = (xhrReadyStateChange); if (this.readyState === 4) { // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) diff --git a/src/internal/observable/pairs.ts b/src/internal/observable/pairs.ts index 8936d07588..d7a3f7e7ca 100644 --- a/src/internal/observable/pairs.ts +++ b/src/internal/observable/pairs.ts @@ -51,7 +51,9 @@ export function pairs(obj: Object, scheduler?: IScheduler): Observable<[strin return new Observable<[string, T]>(subscriber => { const keys = Object.keys(obj); const subscription = new Subscription(); - subscription.add(scheduler.schedule(dispatch, 0, { keys, index: 0, subscriber, subscription, obj })); + subscription.add( + scheduler.schedule<{ keys: string[], index: number, subscriber: Subscriber<[string, T]>, subscription: Subscription, obj: Object }> + (dispatch, 0, { keys, index: 0, subscriber, subscription, obj })); return subscription; }); } diff --git a/src/internal/observable/race.ts b/src/internal/observable/race.ts index 0ca4ba75e9..e25a666317 100644 --- a/src/internal/observable/race.ts +++ b/src/internal/observable/race.ts @@ -66,7 +66,7 @@ export class RaceSubscriber extends OuterSubscriber { } else { for (let i = 0; i < len && !this.hasFirst; i++) { let observable = observables[i]; - let subscription = subscribeToResult(this, observable, observable, i); + let subscription = subscribeToResult(this, observable, observable as any, i); if (this.subscriptions) { this.subscriptions.push(subscription); diff --git a/src/internal/operators/bufferTime.ts b/src/internal/operators/bufferTime.ts index 673cf4d91f..6ccac1d1dd 100644 --- a/src/internal/operators/bufferTime.ts +++ b/src/internal/operators/bufferTime.ts @@ -100,13 +100,18 @@ class Context { closeAction: Subscription; } -type CreationState = { +interface DispatchCreateArg { bufferTimeSpan: number; - bufferCreationInterval: number, + bufferCreationInterval: number; subscriber: BufferTimeSubscriber; scheduler: IScheduler; }; +interface DispatchCloseArg { + subscriber: BufferTimeSubscriber; + context: Context; +} + /** * We need this JSDoc comment for affecting ESDoc. * @ignore @@ -129,9 +134,9 @@ class BufferTimeSubscriber extends Subscriber { this.add(context.closeAction = scheduler.schedule(dispatchBufferTimeSpanOnly, bufferTimeSpan, timeSpanOnlyState)); } else { const closeState = { subscriber: this, context }; - const creationState: CreationState = { bufferTimeSpan, bufferCreationInterval, subscriber: this, scheduler }; - this.add(context.closeAction = scheduler.schedule(dispatchBufferClose, bufferTimeSpan, closeState)); - this.add(scheduler.schedule(dispatchBufferCreation, bufferCreationInterval, creationState)); + const creationState: DispatchCreateArg = { bufferTimeSpan, bufferCreationInterval, subscriber: this, scheduler }; + this.add(context.closeAction = scheduler.schedule>(dispatchBufferClose, bufferTimeSpan, closeState)); + this.add(scheduler.schedule>(dispatchBufferCreation, bufferCreationInterval, creationState)); } } @@ -216,22 +221,17 @@ function dispatchBufferTimeSpanOnly(this: Action, state: any) { } } -interface DispatchArg { - subscriber: BufferTimeSubscriber; - context: Context; -} - -function dispatchBufferCreation(this: Action>, state: CreationState) { +function dispatchBufferCreation(this: Action>, state: DispatchCreateArg) { const { bufferCreationInterval, bufferTimeSpan, subscriber, scheduler } = state; const context = subscriber.openContext(); - const action = >>this; + const action = >>this; if (!subscriber.closed) { - subscriber.add(context.closeAction = scheduler.schedule>(dispatchBufferClose, bufferTimeSpan, { subscriber, context })); + subscriber.add(context.closeAction = scheduler.schedule>(dispatchBufferClose, bufferTimeSpan, { subscriber, context })); action.schedule(state, bufferCreationInterval); } } -function dispatchBufferClose(arg: DispatchArg) { +function dispatchBufferClose(arg: DispatchCloseArg) { const { subscriber, context } = arg; subscriber.closeContext(context); } diff --git a/src/internal/operators/concatMapTo.ts b/src/internal/operators/concatMapTo.ts index b604eac1ac..5471f1ef17 100644 --- a/src/internal/operators/concatMapTo.ts +++ b/src/internal/operators/concatMapTo.ts @@ -64,7 +64,7 @@ export function concatMapTo(observable: ObservableInput, resultSelec * @owner Observable */ export function concatMapTo( - innerObservable: Observable, + innerObservable: ObservableInput, resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R ): OperatorFunction { return concatMap(() => innerObservable, resultSelector); diff --git a/src/internal/operators/expand.ts b/src/internal/operators/expand.ts index 7b0663867c..07b3dac31a 100644 --- a/src/internal/operators/expand.ts +++ b/src/internal/operators/expand.ts @@ -130,7 +130,7 @@ export class ExpandSubscriber extends OuterSubscriber { this.subscribeToProjection(result, value, index); } else { const state: DispatchArg = { subscriber: this, result, value, index }; - this.add(this.scheduler.schedule(ExpandSubscriber.dispatch, 0, state)); + this.add(this.scheduler.schedule>(ExpandSubscriber.dispatch, 0, state)); } } else { this.buffer.push(value); diff --git a/src/internal/operators/groupBy.ts b/src/internal/operators/groupBy.ts index 6fd451c205..af2fe3afbd 100644 --- a/src/internal/operators/groupBy.ts +++ b/src/internal/operators/groupBy.ts @@ -119,7 +119,7 @@ class GroupByOperator implements Operator> { * @extends {Ignored} */ class GroupBySubscriber extends Subscriber implements RefCountSubscription { - private groups: Map> = null; + private groups: Map> = null; public attemptedToUnsubscribe: boolean = false; public count: number = 0; @@ -147,7 +147,7 @@ class GroupBySubscriber extends Subscriber implements RefCountSubscr let groups = this.groups; if (!groups) { - groups = this.groups = new Map>(); + groups = this.groups = new Map>(); } let group = groups.get(key); @@ -164,7 +164,7 @@ class GroupBySubscriber extends Subscriber implements RefCountSubscr } if (!group) { - group = this.subjectSelector ? this.subjectSelector() : new Subject(); + group = (this.subjectSelector ? this.subjectSelector() : new Subject()) as Subject; groups.set(key, group); const groupedObservable = new GroupedObservable(key, group, this); this.destination.next(groupedObservable); @@ -231,7 +231,7 @@ class GroupBySubscriber extends Subscriber implements RefCountSubscr class GroupDurationSubscriber extends Subscriber { constructor(private key: K, private group: Subject, - private parent: GroupBySubscriber) { + private parent: GroupBySubscriber) { super(group); } @@ -265,7 +265,7 @@ export class GroupedObservable extends Observable { protected _subscribe(subscriber: Subscriber) { const subscription = new Subscription(); - const {refCountSubscription, groupSubject} = this; + const { refCountSubscription, groupSubject } = this; if (refCountSubscription && !refCountSubscription.closed) { subscription.add(new InnerRefCountSubscription(refCountSubscription)); } diff --git a/src/internal/operators/mergeMapTo.ts b/src/internal/operators/mergeMapTo.ts index af65bacbbd..194b45bc81 100644 --- a/src/internal/operators/mergeMapTo.ts +++ b/src/internal/operators/mergeMapTo.ts @@ -56,7 +56,7 @@ export function mergeMapTo(observable: ObservableInput, resultSelect * @method mergeMapTo * @owner Observable */ -export function mergeMapTo(innerObservable: Observable, +export function mergeMapTo(innerObservable: ObservableInput, resultSelector?: ((outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R) | number, concurrent: number = Number.POSITIVE_INFINITY): OperatorFunction { if (typeof resultSelector === 'number') { diff --git a/src/internal/operators/refCount.ts b/src/internal/operators/refCount.ts index 126ee54b23..eb8ecd7a02 100644 --- a/src/internal/operators/refCount.ts +++ b/src/internal/operators/refCount.ts @@ -8,7 +8,7 @@ import { Observable } from '../Observable'; export function refCount(): MonoTypeOperatorFunction { return function refCountOperatorFunction(source: ConnectableObservable): Observable { return source.lift(new RefCountOperator(source)); - }; + } as MonoTypeOperatorFunction; } class RefCountOperator implements Operator { diff --git a/src/internal/operators/startWith.ts b/src/internal/operators/startWith.ts index 8b7b0011bb..c7885bc327 100644 --- a/src/internal/operators/startWith.ts +++ b/src/internal/operators/startWith.ts @@ -46,7 +46,7 @@ export function startWith(...array: Array): MonoTypeOperatorF } else if (len > 0) { return concatStatic(fromArray(array as T[], scheduler), source); } else { - return concatStatic(empty(scheduler), source); + return concatStatic(empty(scheduler) as any, source); } }; } diff --git a/src/internal/operators/subscribeOn.ts b/src/internal/operators/subscribeOn.ts index c17846920d..7d3482229b 100644 --- a/src/internal/operators/subscribeOn.ts +++ b/src/internal/operators/subscribeOn.ts @@ -28,7 +28,7 @@ class SubscribeOnOperator implements Operator { private delay: number) { } call(subscriber: Subscriber, source: any): TeardownLogic { - return new SubscribeOnObservable( + return new SubscribeOnObservable( source, this.delay, this.scheduler ).subscribe(subscriber); } diff --git a/src/internal/operators/switchMapTo.ts b/src/internal/operators/switchMapTo.ts index 94c85fd45a..836018fb6a 100644 --- a/src/internal/operators/switchMapTo.ts +++ b/src/internal/operators/switchMapTo.ts @@ -54,7 +54,7 @@ export function switchMapTo(observable: ObservableInput, resultSelec * @method switchMapTo * @owner Observable */ -export function switchMapTo(innerObservable: Observable, +export function switchMapTo(innerObservable: ObservableInput, resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, @@ -63,7 +63,7 @@ export function switchMapTo(innerObservable: Observable, } class SwitchMapToOperator implements Operator { - constructor(private observable: Observable, + constructor(private observable: ObservableInput, private resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R) { } @@ -82,7 +82,7 @@ class SwitchMapToSubscriber extends OuterSubscriber { private innerSubscription: Subscription; constructor(destination: Subscriber, - private inner: Observable, + private inner: ObservableInput, private resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R) { super(destination); } diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index cf6170518e..bb325d54fa 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -91,7 +91,7 @@ class ThrottleTimeSubscriber extends Subscriber { this._hasTrailingValue = true; } } else { - this.add(this.throttled = this.scheduler.schedule(dispatchNext, this.duration, { subscriber: this })); + this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this })); if (this.leading) { this.destination.next(value); } diff --git a/src/internal/operators/timeout.ts b/src/internal/operators/timeout.ts index 54dfd5fc8a..ac52d03910 100644 --- a/src/internal/operators/timeout.ts +++ b/src/internal/operators/timeout.ts @@ -127,7 +127,7 @@ class TimeoutSubscriber extends Subscriber { // to ensure that's the one we clone from next time. this.action = (>> action.schedule(this, this.waitFor)); } else { - this.add(this.action = (>> this.scheduler.schedule( + this.add(this.action = (>> this.scheduler.schedule>( TimeoutSubscriber.dispatchTimeout, this.waitFor, this ))); } diff --git a/src/internal/operators/timeoutWith.ts b/src/internal/operators/timeoutWith.ts index 8660f73270..07df3ed19b 100644 --- a/src/internal/operators/timeoutWith.ts +++ b/src/internal/operators/timeoutWith.ts @@ -120,7 +120,7 @@ class TimeoutWithSubscriber extends OuterSubscriber { // to ensure that's the one we clone from next time. this.action = (>> action.schedule(this, this.waitFor)); } else { - this.add(this.action = (>> this.scheduler.schedule( + this.add(this.action = (>> this.scheduler.schedule>( TimeoutWithSubscriber.dispatchTimeout, this.waitFor, this ))); } diff --git a/src/internal/operators/windowTime.ts b/src/internal/operators/windowTime.ts index c458b95001..9ad659066b 100644 --- a/src/internal/operators/windowTime.ts +++ b/src/internal/operators/windowTime.ts @@ -177,11 +177,11 @@ class WindowTimeSubscriber extends Subscriber { if (windowCreationInterval !== null && windowCreationInterval >= 0) { const closeState: CloseState = { subscriber: this, window, context: null }; const creationState: CreationState = { windowTimeSpan, windowCreationInterval, subscriber: this, scheduler }; - this.add(scheduler.schedule(dispatchWindowClose, windowTimeSpan, closeState)); - this.add(scheduler.schedule(dispatchWindowCreation, windowCreationInterval, creationState)); + this.add(scheduler.schedule>(dispatchWindowClose, windowTimeSpan, closeState)); + this.add(scheduler.schedule>(dispatchWindowCreation, windowCreationInterval, creationState)); } else { const timeSpanOnlyState: TimeSpanOnlyState = { subscriber: this, window, windowTimeSpan }; - this.add(scheduler.schedule(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState)); + this.add(scheduler.schedule>(dispatchWindowTimeSpanOnly, windowTimeSpan, timeSpanOnlyState)); } } @@ -248,7 +248,7 @@ function dispatchWindowCreation(this: Action>, state: Creati const action = this; let context: CloseWindowContext = { action, subscription: null }; const timeSpanState: CloseState = { subscriber, window, context }; - context.subscription = scheduler.schedule(dispatchWindowClose, windowTimeSpan, timeSpanState); + context.subscription = scheduler.schedule>(dispatchWindowClose, windowTimeSpan, timeSpanState); action.add(context.subscription); action.schedule(state, windowCreationInterval); } diff --git a/src/internal/operators/windowToggle.ts b/src/internal/operators/windowToggle.ts index d84a47b4d7..49f9fd1d73 100644 --- a/src/internal/operators/windowToggle.ts +++ b/src/internal/operators/windowToggle.ts @@ -87,7 +87,7 @@ class WindowToggleSubscriber extends OuterSubscriber { private openings: Observable, private closingSelector: (openValue: O) => Observable) { super(destination); - this.add(this.openSubscription = subscribeToResult(this, openings, openings)); + this.add(this.openSubscription = subscribeToResult(this, openings, openings as any)); } protected _next(value: T) { @@ -164,7 +164,7 @@ class WindowToggleSubscriber extends OuterSubscriber { const subscription = new Subscription(); const context = { window, subscription }; this.contexts.push(context); - const innerSubscription = subscribeToResult(this, closingNotifier, context); + const innerSubscription = subscribeToResult(this, closingNotifier, context as any); if (innerSubscription.closed) { this.closeWindow(this.contexts.length - 1); diff --git a/src/internal/patching/operator/combineLatest.ts b/src/internal/patching/operator/combineLatest.ts index 7ba13d8bbb..84e5471c6c 100644 --- a/src/internal/patching/operator/combineLatest.ts +++ b/src/internal/patching/operator/combineLatest.ts @@ -77,5 +77,5 @@ export function combineLatest(this: Observable, ...observables: Arrayobservables[0]).slice(); } - return this.lift.call(of(this, ...observables), new CombineLatestOperator(project)); + return this.lift.call(of(this, ...observables as Array>), new CombineLatestOperator(project)); } diff --git a/src/internal/patching/operator/concatMapTo.ts b/src/internal/patching/operator/concatMapTo.ts index ecf19c79af..53505b363a 100644 --- a/src/internal/patching/operator/concatMapTo.ts +++ b/src/internal/patching/operator/concatMapTo.ts @@ -62,7 +62,7 @@ export function concatMapTo(this: Observable, observable: Observable * @method concatMapTo * @owner Observable */ -export function concatMapTo(this: Observable, innerObservable: Observable, +export function concatMapTo(this: Observable, innerObservable: ObservableInput, resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R): Observable { return higherOrder(innerObservable, resultSelector)(this); } diff --git a/src/internal/patching/operator/mergeMapTo.ts b/src/internal/patching/operator/mergeMapTo.ts index 78b5d0e013..329d45a7d5 100644 --- a/src/internal/patching/operator/mergeMapTo.ts +++ b/src/internal/patching/operator/mergeMapTo.ts @@ -49,7 +49,7 @@ export function mergeMapTo(this: Observable, observable: ObservableI * @method mergeMapTo * @owner Observable */ -export function mergeMapTo(this: Observable, innerObservable: Observable, +export function mergeMapTo(this: Observable, innerObservable: ObservableInput, resultSelector?: ((outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => R) | number, concurrent: number = Number.POSITIVE_INFINITY): Observable { return higherOrder(innerObservable, resultSelector as any, concurrent)(this) as Observable; diff --git a/src/internal/patching/operator/publishLast.ts b/src/internal/patching/operator/publishLast.ts index 50d7062627..e1b5f79641 100644 --- a/src/internal/patching/operator/publishLast.ts +++ b/src/internal/patching/operator/publishLast.ts @@ -8,5 +8,5 @@ import { publishLast as higherOrder } from '../../operators/publishLast'; */ export function publishLast(this: Observable): ConnectableObservable { //TODO(benlesh): correct type-flow through here. - return higherOrder()(this) as ConnectableObservable; + return higherOrder()(this) as ConnectableObservable; } diff --git a/src/internal/patching/operator/scan.ts b/src/internal/patching/operator/scan.ts index c090f30128..9b28cae37c 100644 --- a/src/internal/patching/operator/scan.ts +++ b/src/internal/patching/operator/scan.ts @@ -45,9 +45,11 @@ export function scan(this: Observable, accumulator: (acc: R, value: T, * @method scan * @owner Observable */ -export function scan(this: Observable, accumulator: (acc: R, value: T, index: number) => R, seed?: T | R): Observable { +export function scan(this: Observable, + accumulator: (acc: T | Array | R, value: T, index: number) => T | Array | R, + seed?: T | R): Observable { if (arguments.length >= 2) { return higherOrderScan(accumulator, seed)(this) as Observable; } - return higherOrderScan(accumulator)(this); + return higherOrderScan(accumulator)(this) as Observable; } diff --git a/src/internal/patching/operator/switchMapTo.ts b/src/internal/patching/operator/switchMapTo.ts index b84851fc9e..56749e3c10 100644 --- a/src/internal/patching/operator/switchMapTo.ts +++ b/src/internal/patching/operator/switchMapTo.ts @@ -48,7 +48,7 @@ export function switchMapTo(this: Observable, observable: Observable * @method switchMapTo * @owner Observable */ -export function switchMapTo(this: Observable, innerObservable: Observable, +export function switchMapTo(this: Observable, innerObservable: ObservableInput, resultSelector?: (outerValue: T, innerValue: I, outerIndex: number, diff --git a/src/internal/scheduler/AnimationFrameAction.ts b/src/internal/scheduler/AnimationFrameAction.ts index 16cbb9aa34..67664d9f96 100644 --- a/src/internal/scheduler/AnimationFrameAction.ts +++ b/src/internal/scheduler/AnimationFrameAction.ts @@ -1,6 +1,7 @@ import { AsyncAction } from './AsyncAction'; import { AnimationFrame } from '..//util/AnimationFrame'; import { AnimationFrameScheduler } from './AnimationFrameScheduler'; +import { Action } from './Action'; /** * We need this JSDoc comment for affecting ESDoc. @@ -10,7 +11,7 @@ import { AnimationFrameScheduler } from './AnimationFrameScheduler'; export class AnimationFrameAction extends AsyncAction { constructor(protected scheduler: AnimationFrameScheduler, - protected work: (this: AnimationFrameAction, state?: T) => void) { + protected work: (this: Action, state?: T) => void) { super(scheduler, work); } diff --git a/src/internal/scheduler/AsapAction.ts b/src/internal/scheduler/AsapAction.ts index b1c43e7ce7..50497b0110 100644 --- a/src/internal/scheduler/AsapAction.ts +++ b/src/internal/scheduler/AsapAction.ts @@ -1,6 +1,7 @@ import { Immediate } from '..//util/Immediate'; import { AsyncAction } from './AsyncAction'; import { AsapScheduler } from './AsapScheduler'; +import { Action } from './Action'; /** * We need this JSDoc comment for affecting ESDoc. @@ -10,7 +11,7 @@ import { AsapScheduler } from './AsapScheduler'; export class AsapAction extends AsyncAction { constructor(protected scheduler: AsapScheduler, - protected work: (this: AsapAction, state?: T) => void) { + protected work: (this: Action, state?: T) => void) { super(scheduler, work); } diff --git a/src/internal/scheduler/AsyncAction.ts b/src/internal/scheduler/AsyncAction.ts index 01387cdb24..7dae0297b8 100644 --- a/src/internal/scheduler/AsyncAction.ts +++ b/src/internal/scheduler/AsyncAction.ts @@ -16,7 +16,7 @@ export class AsyncAction extends Action { protected pending: boolean = false; constructor(protected scheduler: AsyncScheduler, - protected work: (this: AsyncAction, state?: T) => void) { + protected work: (this: Action, state?: T) => void) { super(scheduler, work); } diff --git a/src/internal/scheduler/QueueAction.ts b/src/internal/scheduler/QueueAction.ts index 23203b90ab..9387ab6fce 100644 --- a/src/internal/scheduler/QueueAction.ts +++ b/src/internal/scheduler/QueueAction.ts @@ -1,6 +1,7 @@ import { AsyncAction } from './AsyncAction'; import { Subscription } from '../Subscription'; import { QueueScheduler } from './QueueScheduler'; +import { Action } from './Action'; /** * We need this JSDoc comment for affecting ESDoc. @@ -10,7 +11,7 @@ import { QueueScheduler } from './QueueScheduler'; export class QueueAction extends AsyncAction { constructor(protected scheduler: QueueScheduler, - protected work: (this: QueueAction, state?: T) => void) { + protected work: (this: Action, state?: T) => void) { super(scheduler, work); } diff --git a/src/internal/scheduler/VirtualTimeScheduler.ts b/src/internal/scheduler/VirtualTimeScheduler.ts index 5da67912b9..9690efed59 100644 --- a/src/internal/scheduler/VirtualTimeScheduler.ts +++ b/src/internal/scheduler/VirtualTimeScheduler.ts @@ -1,6 +1,7 @@ import { AsyncAction } from './AsyncAction'; import { Subscription } from '../Subscription'; import { AsyncScheduler } from './AsyncScheduler'; +import { Action } from './Action'; export class VirtualTimeScheduler extends AsyncScheduler { @@ -9,7 +10,7 @@ export class VirtualTimeScheduler extends AsyncScheduler { public frame: number = 0; public index: number = -1; - constructor(SchedulerAction: typeof AsyncAction = VirtualAction, + constructor(SchedulerAction: typeof AsyncAction = VirtualAction as any, public maxFrames: number = Number.POSITIVE_INFINITY) { super(SchedulerAction, () => this.frame); } @@ -49,7 +50,7 @@ export class VirtualAction extends AsyncAction { protected active: boolean = true; constructor(protected scheduler: VirtualTimeScheduler, - protected work: (this: VirtualAction, state?: T) => void, + protected work: (this: Action, state?: T) => void, protected index: number = scheduler.index += 1) { super(scheduler, work); this.index = scheduler.index = index; @@ -73,7 +74,7 @@ export class VirtualAction extends AsyncAction { this.delay = scheduler.frame + delay; const {actions} = scheduler; actions.push(this); - actions.sort(VirtualAction.sortActions); + (actions as Array>).sort(VirtualAction.sortActions); return true; } diff --git a/src/internal/testing/ColdObservable.ts b/src/internal/testing/ColdObservable.ts index 6a3309caea..fc3babd6b7 100644 --- a/src/internal/testing/ColdObservable.ts +++ b/src/internal/testing/ColdObservable.ts @@ -20,8 +20,8 @@ export class ColdObservable extends Observable implements SubscriptionLogg constructor(public messages: TestMessage[], scheduler: Scheduler) { - super(function (this: ColdObservable, subscriber: Subscriber) { - const observable: ColdObservable = this; + super(function (this: Observable, subscriber: Subscriber) { + const observable: ColdObservable = this as any; const index = observable.logSubscribedFrame(); subscriber.add(new Subscription(() => { observable.logUnsubscribedFrame(index); @@ -37,9 +37,9 @@ export class ColdObservable extends Observable implements SubscriptionLogg for (let i = 0; i < messagesLength; i++) { const message = this.messages[i]; subscriber.add( - this.scheduler.schedule(({message, subscriber}) => { message.notification.observe(subscriber); }, + this.scheduler.schedule(({ message, subscriber }) => { message.notification.observe(subscriber); }, message.frame, - {message, subscriber}) + { message, subscriber }) ); } } diff --git a/src/internal/util/pipe.ts b/src/internal/util/pipe.ts index d5e7cfd2ce..d4256eb46f 100644 --- a/src/internal/util/pipe.ts +++ b/src/internal/util/pipe.ts @@ -29,6 +29,6 @@ export function pipeFromArray(fns: Array>): UnaryFunct } return function piped(input: T): R { - return fns.reduce((prev: any, fn: UnaryFunction) => fn(prev), input); + return fns.reduce((prev: any, fn: UnaryFunction) => fn(prev), input as any); }; } diff --git a/tsconfig.json b/tsconfig.json index 6d6702f311..ccdc36e281 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "removeComments": false, "preserveConstEnums": true, "sourceMap": true, + "strictFunctionTypes": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true,