Use return type deduction for timers

Fix updates to Node.js timers types breaking the TypeScript build by
deducing the correct type from the return type of the
setTimeout/setInterval functions.
This commit is contained in:
Hornwitser committed 2023-08-15 18:01:27 +02:00
1 parent e51a644788
commit 9c9adf7c8e
6 files changed
+8 -8

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ export default class RateLimiter {
action?: Function;
private _lastRun = 0;
private _runTimeout?: NodeJS.Timeout;
private _runTimeout?: ReturnType<typeof setTimeout>;
/**
* Construct RateLimiter helper
+1 -1
View File
@@ -37,7 +37,7 @@ export async function wait(duration: number) {
* @param {*=} timeoutResult - Value to return if the operation timed out.
*/
export async function timeout<T>(promise: Promise<T>, time: number, timeoutResult: T) {
let timer: NodeJS.Timer | undefined;
let timer: ReturnType<typeof setTimeout> | undefined;
try {
return await Promise.race([
promise,
+3 -3
View File
@@ -99,7 +99,7 @@ export abstract class WebSocketBaseConnector extends BaseConnector {
_closing = false;
_socket: WebSocket | null = null;
_lastHeartbeat: number | null = null;
_heartbeatId: NodeJS.Timer | null = null;
_heartbeatId: ReturnType<typeof setInterval> | null = null;
_heartbeatInterval: number | null = null;
_lastReceivedSeq = undefined;
_sendBuffer: (ReliableMessages)[] = [];
@@ -287,7 +287,7 @@ export abstract class WebSocketBaseConnector extends BaseConnector {
this.setClosing();
this._sendInternal(new libData.MessageDisconnect("prepare"));
let timeout: NodeJS.Timeout | undefined;
let timeout: ReturnType<typeof setTimeout> | undefined;
let waitTimeout = new Promise(resolve => { timeout = setTimeout(resolve, 10000); }); // Make Configurable?
try {
await Promise.race([
@@ -331,7 +331,7 @@ export abstract class WebSocketBaseConnector extends BaseConnector {
* @extends module:lib.WebSocketBaseConnector
*/
export abstract class WebSocketClientConnector extends WebSocketBaseConnector {
_reconnectId?: NodeJS.Timeout;
_reconnectId?: ReturnType<typeof setTimeout>;
_sessionToken: string | null = null;
_sessionTimeout: number | null = null;
_startedResuming: number | null = null;