Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Lesson 9 of 9
Mini Project: Task Manager - Part 1 (Domain Types)
Start the Task Manager - the course-spanning project. In Part 1, scaffold the project, define the domain types (Task, User, Priority, Status), and write your first typed utility functions. Everything here forms the foundation every later module builds on.
Task Manager - Domain Type Scaffold
// src/types/domain.ts
// ── Core domain types ────────────────────────────────────────
// Status as union-of-literals (preferred over enum)
export type TaskStatus = "todo" | "in-progress" | "done" | "archived";
export type Priority = "low" | "medium" | "high" | "critical";
// User domain type
export interface User {
readonly id: number;
name: string;
email: string;
role: "member" | "admin";
createdAt: Date;
}
// Task domain type
export interface Task {
readonly id: number;
title: string;
description: string | null;
status: TaskStatus;
priority: Priority;
assignee: User | null;
dueDate: Date | null;
readonly createdAt: Date;
updatedAt: Date;
tags: readonly string[];
}
// ── src/utils/task.ts ─────────────────────────────────────────
import type { Task, TaskStatus } from "../types/domain";
// Typed utility functions
export function isOverdue(task: Task): boolean {
if (task.dueDate === null) return false;
return task.dueDate < new Date() && task.status !== "done";
}
export function filterByStatus(tasks: Task[], status: TaskStatus): Task[] {
return tasks.filter((t) => t.status === status);
}
export function countByPriority(tasks: Task[]): Record<string, number> {
return tasks.reduce<Record<string, number>>((acc, task) => {
acc[task.priority] = (acc[task.priority] ?? 0) + 1;
return acc;
}, {});
}
// ── src/index.ts ─────────────────────────────────────────────
import { filterByStatus, countByPriority, isOverdue } from "./utils/task";
import type { Task } from "./types/domain";
const tasks: Task[] = [
{
id: 1,
title: "Design system setup",
description: "Configure colour tokens and component library",
status: "in-progress",
priority: "high",
assignee: { id: 1, name: "Alice", email: "alice@co.com", role: "member", createdAt: new Date() },
dueDate: new Date("2026-04-01"),
createdAt: new Date(),
updatedAt: new Date(),
tags: ["design", "ui"],
},
{
id: 2,
title: "Write API docs",
description: null,
status: "todo",
priority: "medium",
assignee: null,
dueDate: null,
createdAt: new Date(),
updatedAt: new Date(),
tags: [],
},
];
console.log("In progress:", filterByStatus(tasks, "in-progress"));
console.log("Overdue tasks:", tasks.filter(isOverdue));
console.log("By priority:", countByPriority(tasks));Visual architecture and concepts for Mini Project: Task Manager - Part 1 (Domain Types)
Common Mistakes
- Making all fields mutable - mark `id`, `createdAt` as `readonly` from the start. These should never change after creation.
- Using `any[]` for task lists - always type arrays with the specific type `Task[]`. Empty arrays should be typed explicitly as `Task[]`, not left to infer as `never[]`.
- Putting business logic in type files - keep `src/types/` for pure type definitions. Utility functions go in `src/utils/`. This separation makes types importable with `import type` which is stripped at compile time, keeping bundle sizes lean.
Key Takeaways
- Start the Task Manager - the course-spanning project.
- Making all fields mutable - mark `id`, `createdAt` as `readonly` from the start. These should never change after creation.
- Using `any[]` for task lists - always type arrays with the specific type `Task[]`. Empty arrays should be typed explicitly as `Task[]`, not left to infer as `never[]`.
- Putting business logic in type files - keep `src/types/` for pure type definitions. Utility functions go in `src/utils/`. This separation makes types importable with `import type` which is stripped at compile time, keeping bundle sizes lean.
Finished this lesson?