diff --git a/src/system/function.ts b/src/system/function.ts index 3d2a317..0b937cf 100644 --- a/src/system/function.ts +++ b/src/system/function.ts @@ -2,9 +2,10 @@ import { Disposable } from 'vscode'; import { debounce as _debounce, once as _once } from 'lodash-es'; -export interface Deferrable { +export interface Deferrable any> { + (...args: Parameters): ReturnType | undefined; cancel(): void; - flush(...args: any[]): void; + flush(): ReturnType | undefined; pending?(): boolean; } @@ -38,7 +39,7 @@ export namespace Functions { fn: T, wait?: number, options?: DebounceOptions, - ): T & Deferrable { + ): Deferrable { const { track, ...opts }: DebounceOptions = { track: false, ...(options ?? {}), @@ -55,12 +56,12 @@ export namespace Functions { } as any) as T, wait, options, - ) as T & Deferrable; + ); - const tracked = (function (this: any, ...args: any[]) { + const tracked: Deferrable = function (this: any, ...args: Parameters) { pending = true; return debounced.apply(this, args); - } as any) as T & Deferrable; + } as any; tracked.pending = function () { return pending; @@ -68,9 +69,8 @@ export namespace Functions { tracked.cancel = function () { return debounced.cancel.apply(debounced); }; - tracked.flush = function (...args: any[]) { - // eslint-disable-next-line prefer-spread - return debounced.flush.apply(debounced, args); + tracked.flush = function () { + return debounced.flush.apply(debounced); }; return tracked; diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index 0a1dc4c..9f4f3aa 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -315,8 +315,8 @@ export class DocumentTracker implements Disposable { return doc; } - private _dirtyIdleTriggeredDebounced: (((e: DocumentDirtyIdleTriggerEvent) => void) & Deferrable) | undefined; - private _dirtyStateChangedDebounced: (((e: DocumentDirtyStateChangeEvent) => void) & Deferrable) | undefined; + private _dirtyIdleTriggeredDebounced: Deferrable<(e: DocumentDirtyIdleTriggerEvent) => void> | undefined; + private _dirtyStateChangedDebounced: Deferrable<(e: DocumentDirtyStateChangeEvent) => void> | undefined; private fireDocumentDirtyStateChanged(e: DocumentDirtyStateChangeEvent) { if (e.dirty) { setImmediate(async () => { diff --git a/src/trackers/lineTracker.ts b/src/trackers/lineTracker.ts index 8b11ff6..d2ce299 100644 --- a/src/trackers/lineTracker.ts +++ b/src/trackers/lineTracker.ts @@ -199,7 +199,7 @@ export class LineTracker implements Disposable { this.onLinesChanged({ editor: this._editor, selections: this.selections, reason: reason }); } - private _linesChangedDebounced: (((e: LinesChangeEvent) => void) & Deferrable) | undefined; + private _linesChangedDebounced: Deferrable<(e: LinesChangeEvent) => void> | undefined; private onLinesChanged(e: LinesChangeEvent) { if (e.selections === undefined) {