fix(insights): narrow Sprint.completed_at to Date in velocity.ts
Vercel build was failing with TS18047 — `sprint.completed_at` is possibly `null`. The earlier `.filter(s => s.completed_at != null)` runtime-filtered the nulls out but did NOT narrow the element type; TypeScript still saw `Date | null` on the result. Add a user-defined type guard `(s): s is SprintWithCompletedAt =>` so the narrowed array carries `completed_at: Date`. No runtime change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b2427fd07b
commit
e39e02a4ac
1 changed files with 6 additions and 1 deletions
|
|
@ -33,7 +33,12 @@ export async function getVelocity(userId: string, sprintsBack = 5): Promise<Velo
|
||||||
})
|
})
|
||||||
|
|
||||||
// Reverse to chronological order (oldest first, for x-axis)
|
// Reverse to chronological order (oldest first, for x-axis)
|
||||||
const chronological = [...sprints].filter(s => s.completed_at != null).reverse()
|
// Type-guard so the narrowed array carries `completed_at: Date` (not Date | null).
|
||||||
|
// A `.filter(s => s.completed_at != null)` alone does NOT narrow the element type.
|
||||||
|
type SprintWithCompletedAt = (typeof sprints)[number] & { completed_at: Date }
|
||||||
|
const chronological = [...sprints]
|
||||||
|
.filter((s): s is SprintWithCompletedAt => s.completed_at != null)
|
||||||
|
.reverse()
|
||||||
|
|
||||||
const result: VelocitySprint[] = chronological.map(sprint => ({
|
const result: VelocitySprint[] = chronological.map(sprint => ({
|
||||||
sprintId: sprint.id,
|
sprintId: sprint.id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue