fix(types): remove non-null assertions in remaining 12 files

Files fixed:
- messages-media.ts: stream/buffer guards, file path validation
- decode-wa-message.ts: message field guards, optional chaining
- version-cache.ts: narrowing after null checks
- jid-utils.ts: split result guards, user fallbacks
- communities.ts: attrs fallbacks with ?? operator
- sticker-pack.ts: response guards
- business.ts: attrs guards
- socket.ts: onClose guard, pairingCode guard, creds.me guard
- event-buffer.ts: null guards
- signal.ts: null guards
- encode.ts (WAM): id null check with continue
- upstream history.ts: conversations/pushnames null guards

All 26 files across the project are now corrected.
Total: ~248 non-null assertions replaced with proper null guards.

https://claude.ai/code/session_01E2cfX1N3sJgCJBTvzGazSG
This commit is contained in:
Claude
2026-02-09 00:32:04 +00:00
parent 7e88ddb858
commit 1c9fb86cc3
12 changed files with 215 additions and 104 deletions
+12 -7
View File
@@ -55,15 +55,15 @@ export const jidEncode = (user: string | number | null, server: JidServer, devic
export const jidDecode = (jid: string | undefined): FullJid | undefined => {
// todo: investigate how to implement hosted ids in this case
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
if (sepIdx < 0) {
if (sepIdx < 0 || !jid) {
return undefined
}
const server = jid!.slice(sepIdx + 1)
const userCombined = jid!.slice(0, sepIdx)
const server = jid.slice(sepIdx + 1)
const userCombined = jid.slice(0, sepIdx)
const [userAgent, device] = userCombined.split(':')
const [user, agent] = userAgent!.split('_')
const [user, agent] = (userAgent ?? '').split('_')
let domainType = WAJIDDomains.WHATSAPP
if (server === 'lid') {
@@ -78,7 +78,7 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => {
return {
server: server as JidServer,
user: user!,
user: user ?? '',
domainType,
device: device ? +device : undefined
}
@@ -114,7 +114,7 @@ export const isAnyPnUser = (jid: string | undefined) =>
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
export const isJidBot = (jid: string | undefined) => jid && botRegexp.test(jid.split('@')[0]!) && jid.endsWith('@c.us')
export const isJidBot = (jid: string | undefined) => jid && botRegexp.test(jid.split('@')[0] ?? '') && jid.endsWith('@c.us')
export const jidNormalizedUser = (jid: string | undefined) => {
const result = jidDecode(jid)
@@ -129,6 +129,11 @@ export const jidNormalizedUser = (jid: string | undefined) => {
export const transferDevice = (fromJid: string, toJid: string) => {
const fromDecoded = jidDecode(fromJid)
const deviceId = fromDecoded?.device || 0
const { server, user } = jidDecode(toJid)!
const toDecoded = jidDecode(toJid)
if (!toDecoded) {
return ''
}
const { server, user } = toDecoded
return jidEncode(user, server, deviceId)
}