diff --git a/lib/insights/velocity.ts b/lib/insights/velocity.ts index 7cf123e..c01c45e 100644 --- a/lib/insights/velocity.ts +++ b/lib/insights/velocity.ts @@ -33,7 +33,12 @@ export async function getVelocity(userId: string, sprintsBack = 5): Promise 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 => ({ sprintId: sprint.id,