fix(sp25): typecheck fixups

Three small follow-ups after the live-tail triplet wired up:

  * evictOldest is now generic over (K extends string|number, V) so
    the addAck / addTa1Ack call sites don't need a type assertion.
  * Acks.test.tsx no longer spreads importOriginal() — TypeScript
    was choking on the inferred 'unknown' from the mock factory.
    Use the same ApiError / mock shape that Claims.test.tsx uses.
  * tail-stream.test.ts guards the optional gen.return() with
    so strict mode TS2722 stops complaining about possibly-undefined.
This commit is contained in:
Nora
2026-07-02 09:23:44 -06:00
parent 146cb6d17d
commit 1363d36046
3 changed files with 16 additions and 12 deletions
+7 -7
View File
@@ -79,11 +79,11 @@ interface TailStore {
*/
type RemitListItem = Remittance;
function evictOldest<T>(
order: Array<string | number>,
dict: Record<string, T>,
function evictOldest<K extends string | number, V>(
order: K[],
dict: Record<string, V>,
batch: number,
): { order: Array<string | number>; dict: Record<string, T> } {
): { order: K[]; dict: Record<string, V> } {
if (order.length <= TAIL_CAP) return { order, dict };
// Drain down to the cap; never evict more than `batch` per call so a
// 5-item overflow evicts 5, but a 1 000-item overflow evicts 100 in
@@ -93,7 +93,7 @@ function evictOldest<T>(
const nextOrder = order.slice(toDrop);
// Object.assign is consistently faster than `{ ...dict }` in V8 for
// large dicts; we follow up with `delete` for each evicted id.
const nextDict: Record<string, T> = Object.assign({}, dict);
const nextDict: Record<string, V> = Object.assign({}, dict);
for (const id of dropped) delete nextDict[String(id)];
return { order: nextOrder, dict: nextDict };
}
@@ -172,7 +172,7 @@ export const useTailStore = create<TailStore>((set) => ({
const nextOrder = s.ackOrder.concat(a.id);
if (nextOrder.length > TAIL_CAP) {
const { order, dict } = evictOldest(nextOrder, nextAcks, EVICT_BATCH);
return { acks: dict, ackOrder: order as number[] };
return { acks: dict, ackOrder: order };
}
return { acks: nextAcks, ackOrder: nextOrder };
}),
@@ -188,7 +188,7 @@ export const useTailStore = create<TailStore>((set) => ({
const nextOrder = s.ta1AckOrder.concat(a.id);
if (nextOrder.length > TAIL_CAP) {
const { order, dict } = evictOldest(nextOrder, nextTa1Acks, EVICT_BATCH);
return { ta1Acks: dict, ta1AckOrder: order as number[] };
return { ta1Acks: dict, ta1AckOrder: order };
}
return { ta1Acks: nextTa1Acks, ta1AckOrder: nextOrder };
}),