TypeDrop

2026-09-07 Challenge

2026-09-07 Easy

Typed Task Queue with Priority & Status Tracking

You're building the background-job manager for a lightweight project management tool. Tasks arrive with different priorities and move through a fixed lifecycle; the UI needs a typed queue that enforces valid status transitions, aggregates task counts by status, and surfaces the next task to process — all with the compiler catching every invalid shape.

Goals

  • Define the `Task` interface with correct optional timestamp fields and union-typed `priority` / `status` properties.
  • Implement `transitionTask` to enforce valid status transitions using `VALID_TRANSITIONS` and return a new Task object without mutating the original.
  • Implement `nextToProcess` to pick the highest-priority pending task, breaking ties by earliest `createdAt`.
  • Implement `summariseByStatus` so every `TaskStatus` key is always present in the returned `Record`, even when the count is zero.
challenge.ts
export type Priority = "low" | "medium" | "high" | "critical";
export type TaskStatus = "pending" | "in-progress" | "done" | "cancelled";

export interface Task {
  id:          string;
  title:       string;
  priority:    Priority;
  status:      TaskStatus;
  createdAt:   number;
  startedAt?:  number;
  finishedAt?: number;
}

// Returns the highest-priority "pending" task, or undefined if the queue is empty.
export function nextToProcess(tasks: ReadonlyArray<Task>): Task | undefined;

// Counts tasks in every status — all four keys are always present.
export function summariseByStatus(tasks: ReadonlyArray<Task>): Record<TaskStatus, number>;
Hints (click to reveal)

Hints

  • Use a `const` priority-rank lookup (`Record<Priority, number>`) inside `nextToProcess` to compare priorities numerically instead of chaining string comparisons.
  • Spread syntax (`{ ...task, status: next }`) is the cleanest way to return an updated Task without mutation — TypeScript will still enforce the shape.
  • Initialise the summary `Record` with all four statuses set to `0` before iterating, so you never need to check for missing keys.

Or clone locally

git clone -b challenge/2026-09-07 https://github.com/niltonheck/typedrop.git