What you are practising: discriminated unions, narrowing, immutability, and map/filter/reduce, pulled together in one integrated exercise.
Accept the assignment, clone your repository, then install the tooling once:
npm install- Open a terminal in the
exercise/folder. - Rename the starter:
mv progress.js progress.ts. - Work through what the compiler surfaces.
- Compile with a bare
npx tsc. Notnpx tsc progress.ts: with a filename argument,tscignorestsconfig.jsonand the strict settings with it. - Run the output:
node progress.js.
This is the last TypeScript exercise of the module and it pulls together sessions 1 to 4. The file contains skeleton functions and a test block. All of them are untyped, and a couple contain runtime bugs that only become obvious once types are applied. Run the starter and compare its output against the data; two things are quietly wrong.
- Rename
progress.jstoprogress.ts. - Model the domain with interfaces and/or type aliases:
- a
Learnerwithid,name, andemail - a
ModuleProgresswith atitleand astatus, discriminated on status:'not-started','in-progress', or'completed'. A completed module has acompletedOn: Date, an in-progress module has alastActivity: Date, and a not-started module has nothing extra. - an
Enrolmentthat links a learner to an array ofModuleProgress
- a
- Implement these functions with correct types:
completedModules(enrolment: Enrolment): ModuleProgress[], returning only completed modulesprogressSummary(enrolment: Enrolment): string, returning a human-readable summary using a discriminated union switchfindLearner(enrolments: Enrolment[], id: string): Enrolment | undefined, using a generic helper if you want
- Use
map,filter, orreduceat least once. - Do not mutate any input.
- Compile with
npx tscand run withnode progress.js.
Keep the exported function names (completedModules, progressSummary, findLearner) — the autograder imports them by name.
- Add an
exhaustivehelper and use it inprogressSummaryso that adding a new module status becomes a compile error. - Add a function that takes an
Enrolmentand returns a newEnrolmentwith one module marked as complete, using the four immutable moves from Part 1 of the session. - Extract the generic
findByIdfrom session 3 and use it insidefindLearner.
npx tsc completes with no errors, node progress.js shows Amara's completed module in the list and a summary with real dates (no undefined), no input is mutated, and your work is committed and pushed.
Every push runs two GitHub Actions checks:
- Type check — runs
npx tscon your exercise under the strict settings, once you have renamed the starter to.ts. - Autograding — runs an automated test suite (Vitest) against your functions and reports a functionality score, plus an automated code-quality review.