A typed task manager
The problem
Write a command-line task manager in TypeScript whose types make it impossible to put a task into an invalid state, with every command parsed from text into a typed command before it runs.
Requirements
- Tasks have an id, a title, a priority from a literal union, optional tags and a due date, and a status modelled as a discriminated union (open, in progress with a start time, done with a finish time)
- Commands (add, start, finish, tag, list, filter, remove) are parsed into a discriminated union with a Result, and invalid commands report a clear error
- Every switch over a status or command ends with a never check
- The task list is saved to and loaded from JSON, checking the loaded data with type guards
- Strict mode is on, with no any and no unchecked as assertions
Technologies
- TypeScript
- Discriminated unions
- Generics
- JSON
Step by step
- Design the Task, Status and Command types before writing any logic.
- Write the parser for each command, returning a Result.
- Write the command handlers with exhaustive switches.
- Add saving and loading, with a type guard for the loaded data.
- Add filtering and sorting with generic helper functions.
Expected result
A small, reliable tool whose types document every rule it follows.
How it is evaluated
- The program compiles in strict mode with no errors and no any
- Invalid commands and corrupted files are reported, never crash the program
- Adding a new status or command produces compile errors where it must be handled
- Helper functions are generic and reused
Ways to improve it
- Add undo with a stack of previous states
- Add recurring tasks with a new status member
- Run it in the browser with a simple page