From 6e394bd540525af3655067c6112b207384efce39 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Feb 2026 01:02:13 +0000 Subject: [PATCH] fix(types): resolve all TypeScript compilation errors from non-null assertion removal Fixes: - chats.ts: revert encodeResult/initial to ! (guaranteed by callback assignment) - groups.ts: fix operator precedence with ?? (wrap +attrs in parens), fix groupId type - messages-recv.ts: extract messageKey.id to local const with fallback - socket.ts: revert onClose! (guaranteed by synchronous callback assignment) - event-buffer.ts: add 'notify' fallback for MessageUpsertType - messages.ts: add filePath const after null guard, fix contextInfo type assertion - noise-handler.ts: restore array index ! (guaranteed by length check) Build now compiles with zero new errors. https://claude.ai/code/session_01E2cfX1N3sJgCJBTvzGazSG --- src/Socket/chats.ts | 4 ++-- src/Socket/groups.ts | 6 +++--- src/Socket/messages-recv.ts | 11 ++++++----- src/Socket/socket.ts | 6 +----- src/Utils/event-buffer.ts | 2 +- src/Utils/messages.ts | 10 ++++++---- src/Utils/noise-handler.ts | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index d472eada..f8ac807f 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -886,8 +886,8 @@ export const makeChatsSocket = (config: SocketConfig) => { const { onMutation } = newAppStateChunkHandler(false) const { mutationMap } = await decodePatches( name, - [{ ...encodeResult?.patch, version: { version: encodeResult?.state?.version } }], - initial ?? { version: 0, hash: Buffer.alloc(0), indexValueMap: {} }, + [{ ...encodeResult!.patch, version: { version: encodeResult!.state.version } }], + initial!, getAppStateSyncKey, config.options, undefined, diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index f4db84a0..7517328c 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -316,7 +316,7 @@ export const extractGroupMetadata = (result: BinaryNode) => { descId = descChild.attrs.id } - const groupId = (group.attrs.id ?? '').includes('@') ? group.attrs.id : jidEncode(group.attrs.id ?? '', 'g.us') + const groupId = (group.attrs.id ?? '').includes('@') ? (group.attrs.id ?? '') : jidEncode(group.attrs.id ?? '', 'g.us') const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add' const metadata: GroupMetadata = { @@ -326,9 +326,9 @@ export const extractGroupMetadata = (result: BinaryNode) => { subject: group.attrs.subject ?? '', subjectOwner: group.attrs.s_o, subjectOwnerPn: group.attrs.s_o_pn, - subjectTime: +group.attrs.s_t ?? '0', + subjectTime: +(group.attrs.s_t ?? '0'), size: group.attrs.size ? +group.attrs.size : getBinaryNodeChildren(group, 'participant').length, - creation: +group.attrs.creation ?? '0', + creation: +(group.attrs.creation ?? '0'), owner: group.attrs.creator ? jidNormalizedUser(group.attrs.creator) : undefined, ownerPn: group.attrs.creator_pn ? jidNormalizedUser(group.attrs.creator_pn) : undefined, owner_country_code: group.attrs.creator_country_code, diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index f01961fb..6c6a3efa 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -156,16 +156,17 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { throw new Boom('Not authenticated') } - if (await placeholderResendCache.get(messageKey?.id)) { + const msgId = messageKey?.id ?? '' + if (await placeholderResendCache.get(msgId)) { logger.debug({ messageKey }, 'already requested resend') return } else { - await placeholderResendCache.set(messageKey?.id, true) + await placeholderResendCache.set(msgId, true) } await delay(2000) - if (!(await placeholderResendCache.get(messageKey?.id))) { + if (!(await placeholderResendCache.get(msgId))) { logger.debug({ messageKey }, 'message received while resend requested') return 'RESOLVED' } @@ -180,9 +181,9 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } setTimeout(async () => { - if (await placeholderResendCache.get(messageKey?.id)) { + if (await placeholderResendCache.get(msgId)) { logger.debug({ messageKey }, 'PDO message without response after 8 seconds. Phone possibly offline') - await placeholderResendCache.del(messageKey?.id) + await placeholderResendCache.del(msgId) } }, 8_000) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index f932eab3..0b4f779b 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -552,11 +552,7 @@ export const makeSocket = (config: SocketConfig) => { }) if (sendMsg) { - if (!onClose) { - throw new Error('onClose handler not initialized') - } - - sendRawMessage(sendMsg).catch(onClose) + sendRawMessage(sendMsg).catch(onClose!) } return result diff --git a/src/Utils/event-buffer.ts b/src/Utils/event-buffer.ts index c18be26e..208153f6 100644 --- a/src/Utils/event-buffer.ts +++ b/src/Utils/event-buffer.ts @@ -1265,7 +1265,7 @@ function consolidateEvents(data: BufferedEventData) { const messageUpsertList = Object.values(data.messageUpserts) if (messageUpsertList.length) { - const type = messageUpsertList[0]?.type + const type = messageUpsertList[0]?.type ?? 'notify' map['messages.upsert'] = { messages: messageUpsertList.map(m => m.message), type diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index bd54de01..4e5f71d9 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -264,9 +264,11 @@ export const prepareWAMessageMedia = async ( throw new Boom('Missing file path for processing') } + const filePath = originalFilePath! + if (requiresThumbnailComputation) { const { thumbnail, originalImageDimensions } = await generateThumbnail( - originalFilePath, + filePath, mediaType as 'image' | 'video', options ) @@ -281,12 +283,12 @@ export const prepareWAMessageMedia = async ( } if (requiresDurationComputation) { - uploadData.seconds = await getAudioDuration(originalFilePath) + uploadData.seconds = await getAudioDuration(filePath) logger?.debug('computed audio duration') } if (requiresWaveformProcessing) { - uploadData.waveform = await getAudioWaveform(originalFilePath, logger) + uploadData.waveform = await getAudioWaveform(filePath, logger) logger?.debug('processed waveform') } @@ -1767,7 +1769,7 @@ export const generateWAMessageFromContent = ( const innerContent = innerMessage[key as Exclude] const contextInfo: proto.IContextInfo = - (innerContent && 'contextInfo' in innerContent && innerMessage[key as Exclude]?.contextInfo) || {} + (innerContent && typeof innerContent === 'object' && 'contextInfo' in innerContent && (innerContent as Record).contextInfo as proto.IContextInfo) || {} contextInfo.participant = jidNormalizedUser(participant ?? '') contextInfo.stanzaId = quoted.key.id contextInfo.quotedMessage = quotedMsg diff --git a/src/Utils/noise-handler.ts b/src/Utils/noise-handler.ts index f51eebac..1fad4594 100644 --- a/src/Utils/noise-handler.ts +++ b/src/Utils/noise-handler.ts @@ -150,7 +150,7 @@ export const makeNoiseHandler = ({ while (true) { if (inBytes.length < 3) return - size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2] + size = (inBytes[0]! << 16) | (inBytes[1]! << 8) | inBytes[2]! if (inBytes.length < size + 3) return