Utility Types and Domain Boundaries
Use Pick/Omit/Partial deliberately instead of making domain entities loosely optional.
What you must be able to do
Objectives
Understand the idea before syntax
Move from working JavaScript to explicit compile-time contracts, then learn where runtime validation must take over.
Establish a healthy baseline
- 01
Open a scratch file or the relevant TaskFlow package.
- 02
Run the existing project/tests once so you know the baseline is healthy.
- 03
State what evidence will prove success before changing code.
Small change, immediate evidence
- 01
Write the goal in observable terms before coding: by the end of this lesson you should be able to demonstrate “Utility Types and Domain Boundaries” in a running TaskFlow-oriented example.
- 02
Read the example once without running it. Predict the exact output, state change, request, or compiler behavior and write that prediction down.
- 03
Type the example yourself rather than pasting it. Run the narrowest command that exercises only this concept, then compare observed evidence with your prediction.
- 04
Change one assumption at a time. Keep the change small enough that you can explain why the result changed.
- 05
Perform the intentional failure lab: Use Partial<Task> for updates and identify which server-owned fields become accidentally writable.
- 06
Read the resulting compiler error, stack trace, HTTP response, browser evidence, database state, or CI log from the first line that is actually relevant to your code.
- 07
Repair only the root cause. Re-run the same verification so you can prove the repair changed the observed evidence.
- 08
Close the reference and rebuild the important part from memory. If you cannot explain why each boundary exists, revisit the smallest missing concept rather than memorizing the final code.
type Task = { id: string; title: string; done: boolean; createdAt: Date };
type CreateTaskInput = Pick<Task, "title">;
type UpdateTaskInput = Partial<Pick<Task, "title" | "done">>;Creation cannot provide id/createdAt, updates can provide only mutable fields.
Use Partial<Task> for updates and identify which server-owned fields become accidentally writable.
Do not fix it immediately. Capture the compiler error, request/response, stack trace, database state, browser output, or CI log first. Debugging skill grows from comparing evidence with a prior prediction.
Investigation checklist
- What did you predict?
- What actually happened?
- At what boundary do those first differ?
- What is the smallest piece of evidence that proves the failure lives there?
- Can you fix the cause without changing unrelated layers?
- Can you add a regression test or repeatable verification?
Now work without the transcript
Apply Utility Types and Domain Boundaries to one new TaskFlow requirement. Do not reopen the example until you have a failing attempt, an explanation of the failure, and a specific question you cannot answer.
Continue only when these are true
Mastery evidence
Record this deep-dive lesson
Mark complete only after the transfer challenge and exit ticket.