TypeDrop
2026-05-23 Challenge
2026-05-23
Easy
Typed Task Priority Queue
You're building the scheduling layer for a project management tool. Tasks arrive as `unknown` from a REST API; your engine must validate them, insert them into a typed priority queue, and drain them in order — returning a strongly-typed execution plan with zero `any`.
Goals
- Implement `isValidPriority` as a proper type-guard that narrows `unknown` to `Priority`.
- Implement `validateTask` to parse `unknown` input into a well-typed `Task`, throwing descriptive `TypeError`s for each invalid field.
- Implement `TaskQueue` with `insert`, `drain` (stable priority sort), and a `size` getter — using no `any`.
- Implement `buildExecutionPlan` to validate all raw tasks, drain the queue in priority order, and return a fully-typed `ExecutionPlan` where every `Priority` key is present in `taskCountByPriority`.
challenge.ts
/** Raw priority levels accepted by the API. */
type Priority = "low" | "medium" | "high" | "critical";
type Task = {
id: string;
title: string;
priority: Priority;
durationMin: number; // must be > 0
tags: readonly string[];
};
type ExecutionPlan = {
orderedTasks: readonly Task[]; // critical → high → medium → low
totalDurationMin: number;
taskCountByPriority: Record<Priority, number>;
};
/** Ordered priority levels — highest first. */
const PRIORITY_ORDER = ["critical", "high", "medium", "low"] as const;
// Your main entry point:
function buildExecutionPlan(rawTasks: unknown[]): ExecutionPlan { /* TODO */ }
Hints (click to reveal)
Hints
- Use `PRIORITY_ORDER.indexOf(a.priority) - PRIORITY_ORDER.indexOf(b.priority)` as your sort comparator — a stable sort preserves insertion order for equal priorities.
- To ensure every `Priority` key is always present in `taskCountByPriority`, initialise the `Record` with all four keys set to `0` before counting.
- Inside `validateTask`, narrow `raw` to `Record<string, unknown>` after the non-null object check so you can safely access named fields without `any`.
Useful resources
Or clone locally
git clone -b challenge/2026-05-23 https://github.com/niltonheck/typedrop.git