Use unknown return type for callbacks

This commit is contained in:
Andras Schmelczer 2025-08-17 15:12:31 +01:00
parent e73f147fbc
commit 81b81e30ff
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
16 changed files with 95 additions and 76 deletions

View file

@ -331,6 +331,8 @@ export class Database {
),
lastSeenUpdateId: this.lastSeenUpdateIds.min,
hasInitialSyncCompleted: this.hasInitialSyncCompleted
}).catch((error: unknown) => {
this.logger.error(`Error saving data: ${error}`);
});
}

View file

@ -28,7 +28,7 @@ export class Settings {
private readonly onSettingsChangeHandlers: ((
newSettings: SyncSettings,
oldSettings: SyncSettings
) => void)[] = [];
) => unknown)[] = [];
public constructor(
private readonly logger: Logger,
@ -50,7 +50,7 @@ export class Settings {
}
public addOnSettingsChangeListener(
handler: (settings: SyncSettings, oldSettings: SyncSettings) => void
handler: (settings: SyncSettings, oldSettings: SyncSettings) => unknown
): void {
this.onSettingsChangeHandlers.push(handler);
}

View file

@ -7,8 +7,8 @@ export class ConnectionStatus {
private static readonly UNTIL_RESOLUTION = Symbol();
private canFetch: boolean;
private until: Promise<symbol>;
private resolveUntil: (result: symbol) => void;
private rejectUntil: (reason: unknown) => void;
private resolveUntil: (result: symbol) => unknown;
private rejectUntil: (reason: unknown) => unknown;
public constructor(
settings: Settings,

View file

@ -64,12 +64,12 @@ export class WebSocketManager {
);
}
public addWebSocketStatusChangeListener(listener: () => void): void {
public addWebSocketStatusChangeListener(listener: () => unknown): void {
this.webSocketStatusChangeListeners.push(listener);
}
public addRemoteCursorsUpdateListener(
listener: (cursors: ClientCursors[]) => void
listener: (cursors: ClientCursors[]) => unknown
): void {
this.remoteCursorsUpdateListeners.push(listener);
}

View file

@ -48,9 +48,9 @@ export class SyncClient {
private readonly fileOperations: FileOperations
) {
this.settings.addOnSettingsChangeListener(
(newSettings, oldSettings) => {
async (newSettings, oldSettings) => {
if (newSettings.vaultName !== oldSettings.vaultName) {
void this.reset();
await this.reset();
}
}
);
@ -197,7 +197,7 @@ export class SyncClient {
}
public addSyncHistoryUpdateListener(
listener: (stats: HistoryStats) => void
listener: (stats: HistoryStats) => unknown
): void {
this.history.addSyncHistoryUpdateListener(listener);
}
@ -227,7 +227,7 @@ export class SyncClient {
this.database.reset();
this._logger.reset();
this.connectionStatus.finishReset();
void this.start();
await this.start();
}
public getSettings(): SyncSettings {
@ -246,18 +246,18 @@ export class SyncClient {
}
public addOnSettingsChangeListener(
handler: (settings: SyncSettings, oldSettings: SyncSettings) => void
handler: (settings: SyncSettings, oldSettings: SyncSettings) => unknown
): void {
this.settings.addOnSettingsChangeListener(handler);
}
public addRemainingSyncOperationsListener(
listener: (remainingOperations: number) => void
listener: (remainingOperations: number) => unknown
): void {
this.syncer.addRemainingOperationsListener(listener);
}
public addWebSocketStatusChangeListener(listener: () => void): void {
public addWebSocketStatusChangeListener(listener: () => unknown): void {
this.webSocketManager.addWebSocketStatusChangeListener(listener);
}
@ -344,7 +344,7 @@ export class SyncClient {
}
public addRemoteCursorsUpdateListener(
listener: (cursors: DocumentWithMaybeOutdatedClientCursors[]) => void
listener: (cursors: DocumentWithMaybeOutdatedClientCursors[]) => unknown
): void {
this.webSocketManager.addRemoteCursorsUpdateListener(async () => {
listener(await this.getRelevantClientCursors());

View file

@ -22,7 +22,7 @@ export class Syncer {
private readonly remoteDocumentsLock: Locks<DocumentId>;
private readonly remainingOperationsListeners: ((
remainingOperations: number
) => void)[] = [];
) => unknown)[] = [];
private readonly syncQueue: PQueue;
private runningScheduleSyncForOfflineChanges: Promise<void> | undefined;
@ -57,7 +57,7 @@ export class Syncer {
}
public addRemainingOperationsListener(
listener: (remainingOperations: number) => void
listener: (remainingOperations: number) => unknown
): void {
this.remainingOperationsListeners.push(listener);
}

View file

@ -23,9 +23,11 @@ export class LogLine {
export class Logger {
private static readonly MAX_MESSAGES = 100000;
private readonly messages: LogLine[] = [];
private readonly onMessageListeners: ((message: LogLine) => void)[] = [];
private readonly onMessageListeners: ((message: LogLine) => unknown)[] = [];
public constructor(...onMessageListeners: ((message: LogLine) => void)[]) {
public constructor(
...onMessageListeners: ((message: LogLine) => unknown)[]
) {
this.onMessageListeners = onMessageListeners;
}
@ -53,7 +55,7 @@ export class Logger {
);
}
public addOnMessageListener(listener: (message: LogLine) => void): void {
public addOnMessageListener(listener: (message: LogLine) => unknown): void {
this.onMessageListeners.push(listener);
}

View file

@ -70,7 +70,7 @@ export class SyncHistory {
private readonly syncHistoryUpdateListeners: ((
status: HistoryStats
) => void)[] = [];
) => unknown)[] = [];
private status: HistoryStats = {
success: 0,
@ -111,7 +111,7 @@ export class SyncHistory {
}
public addSyncHistoryUpdateListener(
listener: (stats: HistoryStats) => void
listener: (stats: HistoryStats) => unknown
): void {
this.syncHistoryUpdateListeners.push(listener);
listener({ ...this.status });

View file

@ -2,13 +2,13 @@
* A type-safe utility function to create a Promise with resolve and reject functions.
* @returns A tuple containing a Promise, a resolve function, and a reject function.
*/
export function createPromise<T = void>(): [
export function createPromise<T = unknown>(): [
Promise<T>,
(value: T) => void,
(error: unknown) => void
(value: T) => unknown,
(error: unknown) => unknown
] {
let resolve: undefined | ((resolved: T) => void) = undefined;
let reject: undefined | ((error: unknown) => void) = undefined;
let resolve: undefined | ((resolved: T) => unknown) = undefined;
let reject: undefined | ((error: unknown) => unknown) = undefined;
const creationPromise = new Promise<T>(
(resolve_, reject_) => ((resolve = resolve_), (reject = reject_))