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.
This commit is contained in:
parent
a298fa22f6
commit
3c5f308487
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user