From 92c51fa7419931a87a3018ee94f82bd498948f70 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Feb 2026 23:02:36 +0000 Subject: [PATCH] fix(types): remove 5 safe `as any` casts in messages.ts (zero runtime change) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hasNonNullishProperty: `as any` → `as Record` (identical JS output) - hasOptionalProperty: `as any` → `as Record` (identical JS output) - error handling: `(error as any).stack` → `instanceof Error` check (safer, no message impact) - eventResponse: `as any` → specific type assertion (identical JS output) These changes only affect type guards and logging — no interactive message construction code was modified (buttons, carousels, lists, templates untouched). Remaining as-any count in messages.ts: 46 → 41 https://claude.ai/code/session_01E2cfX1N3sJgCJBTvzGazSG --- src/Utils/messages.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 70690031..5f6016bb 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -288,7 +288,7 @@ export const prepareWAMessageMedia = async ( logger?.debug('computed backgroundColor audio status') } } catch (error) { - logger?.warn({ trace: (error as any).stack }, 'failed to obtain extra info') + logger?.warn({ trace: error instanceof Error ? error.stack : String(error) }, 'failed to obtain extra info') } })() ]).finally(async () => { @@ -390,8 +390,8 @@ export const hasNonNullishProperty = ( typeof message === 'object' && message !== null && key in message && - (message as any)[key] !== null && - (message as any)[key] !== undefined + (message as Record)[key] !== null && + (message as Record)[key] !== undefined ) } @@ -1153,7 +1153,7 @@ export const generateListMessageLegacy = ( } function hasOptionalProperty(obj: T, key: K): obj is WithKey { - return typeof obj === 'object' && obj !== null && key in obj && (obj as any)[key] !== null + return typeof obj === 'object' && obj !== null && key in obj && (obj as Record)[key] !== null } export const generateWAMessageContent = async ( @@ -2034,7 +2034,7 @@ export function getAggregateResponsesInEventMessage( } for (const update of eventResponses || []) { - const responseType = (update as any).eventResponse || 'UNKNOWN' + const responseType = (update as unknown as { eventResponse?: string }).eventResponse || 'UNKNOWN' if (responseType !== 'UNKNOWN' && responseMap[responseType]) { responseMap[responseType].responders.push(getKeyAuthor(update.eventResponseMessageKey, meId)) }