From 3c5f308487fe04e66a7d58014cb6a2d7d35bc951 Mon Sep 17 00:00:00 2001 From: Nora Date: Tue, 10 Mar 2026 06:01:49 +0000 Subject: [PATCH] fix(slack-stream): capture lastStreamPayload into const before null-check + spread Both tsc and tsgo fail to narrow a mutable let variable through a spread expression regardless of guards or non-null assertions. The fix: assign the outer let to a block-scoped const, then check the const !== null in a separate if. TypeScript always narrows a const through a distinct null check so the spread is accepted by all compiler variants. --- src/slack/monitor/message-handler/dispatch.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/slack/monitor/message-handler/dispatch.ts b/src/slack/monitor/message-handler/dispatch.ts index 4a8d8b8c43e..4d739bc5354 100644 --- a/src/slack/monitor/message-handler/dispatch.ts +++ b/src/slack/monitor/message-handler/dispatch.ts @@ -553,11 +553,13 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag } // Fall back to normal delivery with the full accumulated streamed text // so the user receives the complete answer even when stop() fails. - // lastStreamPayload is guarded by !== null above; the ! assertion is - // required because tsc does not narrow mutable let variables through - // spread expressions even with an explicit null guard. - if (orphanDeleted && lastStreamPayload !== null && streamedText) { - await deliverNormally({ ...lastStreamPayload!, text: streamedText }, finalStream.threadTs); + // Use a nested const + if so TypeScript can narrow the type of the + // captured const (not the outer mutable let) before the spread. + if (orphanDeleted && streamedText) { + const fallback = lastStreamPayload; + if (fallback !== null) { + await deliverNormally({ ...fallback, text: streamedText }, finalStream.threadTs); + } } } }