TypeDrop
2026-07-09 Challenge
2026-07-09
Easy
Typed Task Queue Prioritizer
You're building the task scheduling module for a background job runner. Raw task definitions arrive as `unknown` from a job submission API; your module must validate them into strongly-typed `Task` records, sort them by priority and submission time, and return a fully-typed `ScheduleResult` — with zero `any`.
Goals
- Implement `validateTask` to narrow `unknown` → `Task` with ordered field checks, returning a descriptive error string on the first failure found.
- Implement `buildSchedule` to process a batch of raw inputs, collecting typed `ValidationError` entries for each invalid item.
- Sort valid tasks by priority tier (critical → normal → low) and then by `submittedAt` ascending within the same tier.
- Populate `countByPriority` as a `Record<Priority, number>` tallying valid tasks per tier.
challenge.ts
export type Priority = "critical" | "normal" | "low";
export interface Task {
id: string;
name: string;
priority: Priority;
submittedAt: string; // ISO-8601
timeoutMs: number; // must be > 0
metadata: Record<string, string>;
}
export interface ScheduleResult {
queue: Task[]; // sorted: critical → normal → low, then oldest-first
errors: ValidationError[];
totalReceived: number;
countByPriority: Record<Priority, number>;
}
// Validate one raw unknown value → Task on success, error string on failure
export function validateTask(raw: unknown): Task | string { ... }
// Process a batch of raw inputs into a fully-typed ScheduleResult
export function buildSchedule(raws: unknown[]): ScheduleResult { ... }
Hints (click to reveal)
Hints
- Use `PRIORITY_ORDER.includes(...)` to check if a value is a valid `Priority` — you may need a type predicate or a cast-free membership check via `(PRIORITY_ORDER as readonly string[]).includes(val)`.
- For metadata validation, `Object.entries` lets you iterate key-value pairs and check that every value satisfies `typeof v === 'string'`.
- The sort comparator can look up each task's tier weight with `PRIORITY_ORDER.indexOf(task.priority)`, then fall back to a `Date` comparison for tie-breaking.
Useful resources
Or clone locally
git clone -b challenge/2026-07-09 https://github.com/niltonheck/typedrop.git