Use ReturnType<typeof setInterval> for timerIds (#5060)

* Use ReturnType<typeof setInterval> for timerIds

* Remove as number casts for clearInterval
This commit is contained in:
Jaco
2022-07-12 08:31:50 +03:00
committed by GitHub
parent 2548601c9f
commit aa5cc1eef1
3 changed files with 6 additions and 12 deletions
+2 -4
View File
@@ -29,8 +29,7 @@ function textToString (t: Text): string {
} }
export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> { export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
// Browser/Deno = number, Node = Timeout #healthTimer: ReturnType<typeof setInterval> | null = null;
#healthTimer: unknown | null = null;
#registries: VersionedRegistry<ApiType>[] = []; #registries: VersionedRegistry<ApiType>[] = [];
@@ -374,8 +373,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
private _unsubscribeHealth (): void { private _unsubscribeHealth (): void {
if (this.#healthTimer) { if (this.#healthTimer) {
// different method signatures for Node vs Browser/Deno clearInterval(this.#healthTimer);
clearInterval(this.#healthTimer as number);
this.#healthTimer = null; this.#healthTimer = null;
} }
} }
+2 -4
View File
@@ -44,8 +44,7 @@ export class MockProvider implements ProviderInterface {
private emitter = new EventEmitter(); private emitter = new EventEmitter();
// Browser/Deno = number, Node = Timeout private intervalId?: ReturnType<typeof setInterval> | null;
private intervalId?: unknown | null;
public isUpdating = true; public isUpdating = true;
@@ -110,8 +109,7 @@ export class MockProvider implements ProviderInterface {
// eslint-disable-next-line @typescript-eslint/require-await // eslint-disable-next-line @typescript-eslint/require-await
public async disconnect (): Promise<void> { public async disconnect (): Promise<void> {
if (this.intervalId) { if (this.intervalId) {
// different method signatures for Node vs Browser/Deno clearInterval(this.intervalId);
clearInterval(this.intervalId as number);
this.intervalId = null; this.intervalId = null;
} }
} }
+2 -4
View File
@@ -106,8 +106,7 @@ export class WsProvider implements ProviderInterface {
#subscriptions: Record<string, WsStateSubscription> = {}; #subscriptions: Record<string, WsStateSubscription> = {};
// Browser/Deno = number, Node = Timeout #timeoutId?: ReturnType<typeof setInterval> | null = null;
#timeoutId?: unknown | null = null;
#websocket: WebSocket | null; #websocket: WebSocket | null;
@@ -431,8 +430,7 @@ export class WsProvider implements ProviderInterface {
} }
if (this.#timeoutId) { if (this.#timeoutId) {
// different method signatures for Node vs Browser/Deno clearInterval(this.#timeoutId);
clearInterval(this.#timeoutId as number);
this.#timeoutId = null; this.#timeoutId = null;
} }