From 78f130d49b27b6b95cfdbe5baceb38c77663c773 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Feb 2026 02:24:10 +0000 Subject: [PATCH] fix(typescript): resolve compilation errors for production build Fixes 4 TypeScript compilation errors preventing successful build: ## Errors Fixed ### 1. lid-mapping.ts:799 - Property 'metricsModule' does not exist **Error**: `this.metricsModule = null` in destroy() but property never declared **Fix**: Removed orphaned line from previous metrics cleanup **Impact**: Allows successful compilation ### 2-3. socket.ts:795,817 - Connection handler type mismatch **Error**: `{ connection: any }` not assignable to `Partial` **Cause**: Destructuring makes 'connection' required but it's optional in Partial **Fix**: Changed handlers to `(update: Partial)` **Impact**: Proper type safety for connection.update events ### 4. event-buffer.ts:430 - Wrong argument order **Error**: Object passed as second arg but logger expects (obj, msg) order **Fix**: Swapped arguments to `logger.debug({ queuedCount }, 'message')` **Impact**: Matches logger signature from structured-logger.ts ## Root Cause Analysis All errors stem from incremental changes where: - Removed metrics support but missed cleanup reference - Added connection handlers without checking Partial semantics - Used logger without verifying parameter order ## Testing Build verification: ```bash npm run build # Should now complete successfully ``` These are compilation errors only - no runtime behavior changes. https://claude.ai/code/session_VMxqX --- src/Signal/lid-mapping.ts | 3 --- src/Socket/socket.ts | 14 +++++++------- src/Utils/event-buffer.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Signal/lid-mapping.ts b/src/Signal/lid-mapping.ts index 66b064fb..474d65aa 100644 --- a/src/Signal/lid-mapping.ts +++ b/src/Signal/lid-mapping.ts @@ -795,9 +795,6 @@ export class LIDMappingStore { // Clear cache this.mappingCache.clear() - // Clear metrics module reference - this.metricsModule = null - this.logger.debug('LIDMappingStore destroyed successfully') } diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 86c3e510..7467e8f0 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -12,7 +12,7 @@ import { NOISE_WA_HEADER, UPLOAD_TIMEOUT } from '../Defaults' -import type { LIDMapping, SocketConfig } from '../Types' +import type { ConnectionState, LIDMapping, SocketConfig } from '../Types' import { DisconnectReason } from '../Types' import { addTransactionCapability, @@ -777,11 +777,11 @@ export const makeSocket = (config: SocketConfig) => { // PROTECTION 4: Initial delay (avoid duplicate at startup) // CB:success already calls uploadPreKeysToServerIfRequired(), so wait 6h before first auto-sync - const connectionHandler = ({ connection }: { connection: any }) => { - if (connection === 'open') { + const connectionHandler = (update: Partial) => { + if (update.connection === 'open') { logger.info('🔑 Starting PreKey auto-sync timer (first sync in 6h)') syncTimer = setTimeout(syncLoop, SYNC_INTERVAL) - } else if (connection === 'close') { + } else if (update.connection === 'close') { // PROTECTION 5: Cleanup on disconnect if (syncTimer) { clearTimeout(syncTimer) @@ -814,8 +814,8 @@ export const makeSocket = (config: SocketConfig) => { * Returns cleanup function to remove event listener */ const startSessionTTL = () => { - const connectionHandler = ({ connection }: { connection: any }) => { - if (connection === 'open') { + const connectionHandler = (update: Partial) => { + if (update.connection === 'open') { sessionStartTime = Date.now() // PROTECTION 1: Long TTL (7 days) @@ -840,7 +840,7 @@ export const makeSocket = (config: SocketConfig) => { const ttlHours = SESSION_TTL / 1000 / 60 / 60 logger.info(`🕐 Session TTL started (${ttlHours}h = 7 days)`) - } else if (connection === 'close') { + } else if (update.connection === 'close') { // PROTECTION 4: Cleanup ALL timers on disconnect if (ttlTimer) { clearTimeout(ttlTimer) diff --git a/src/Utils/event-buffer.ts b/src/Utils/event-buffer.ts index 612f9f1b..189cb1d1 100644 --- a/src/Utils/event-buffer.ts +++ b/src/Utils/event-buffer.ts @@ -427,7 +427,7 @@ export const makeEventBuffer = ( if (config.enableMetrics) { import('./prometheus-metrics').then(m => { metricsModule = m - logger.debug('📊 Prometheus metrics loaded, flushing buffered metrics', { queuedCount: metricsQueue.length }) + logger.debug({ queuedCount: metricsQueue.length }, '📊 Prometheus metrics loaded, flushing buffered metrics') // Flush buffered metrics metricsQueue.forEach(fn => fn()) metricsQueue = []