fix(slack-stream): non-null assertion for lastStreamPayload spread

tsc does not narrow mutable let variables through spread type expressions
even when an explicit !== null guard precedes the spread. The assertion is
safe — lastStreamPayload !== null is checked in the same condition.
This commit is contained in:
Nora 2026-03-10 05:48:43 +00:00 committed by Vincent Koc
parent 7b9fc01fba
commit a298fa22f6

View File

@ -553,8 +553,11 @@ 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);
await deliverNormally({ ...lastStreamPayload!, text: streamedText }, finalStream.threadTs);
}
}
}