Utility Types & Keyof
Utility Types & Keyof: Utility types are like ready-made patterns a tailor keeps on hand — instead of stitching the original garment (the type) from scratch, you take the existin
Utility types are like ready-made patterns a tailor keeps on hand — instead of stitching the original garment (the type) from scratch, you take the existing pattern and say 'remove all the buttons' (Partial), 'keep only the collar' (Pick), or 'cut off the sleeve' (Omit), deriving a new type. So why not just write a brand-new interface by hand for each of these transformations? Because a type like `UpdateUserPayload` (all fields optional) derived manually from `User` becomes a separate copy that has to be kept in sync by hand whenever `User` changes — easy to forget; `Partial ` instead updates automatically as the original type changes. In Java this was usually done by writing new classes by hand or via a library (like Lombok); TypeScript builds it into the language itself. The concrete QA payoff: for a PATCH request where a test scenario only updates a user's `email` field, using `Partial ` avoids the old type's error about other required fields being missing, while still catching it at compile time if you typo a field name.
Micro Lab: TypeScript coding practice
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
Utility types — type surgery tools
Pick keeps only those fields; Omit removes that field
Partial and Required
Partial makes all fields optional — ideal for update payloads
Record — creates a key-value map type
Order correct utility type matches by use case:
API update payload → Partial
Show only id+name → Pick
All fields except password → Omit
Test results map → Record
In function updateTest(id: number, changes: Partial >), what does Partial > do?