Project: form validation library
Request
The scheduling team needs a reusable validation function for group visit requests.
Data
Requests can contain email, seats, note, and accepted fields. The fixture data is fictional. Rules and bounds are product requirements for this exercise, not medical guidance.
Deliverable
A validator that returns stable field:rule messages, collects independent failures, and checks cross-field requirements without throwing on wrong value types.
A small clinic scheduling team needs a booking form that explains every problem in one response. Returning after the first error forces users to submit repeatedly. Collecting errors without an order creates unstable displays and brittle tests. You will build an ordered validator whose messages identify both the field and the failed rule.
Start with required text, then add format checks, integer validation, inclusive numeric bounds, optional notes, explicit consent, a cross-field group rule, and unknown-field detection. The input is parsed JSON, so treat its values as unknown until their runtime type is checked. A string that looks numeric is still a string. Each release adds one rule while preserving earlier behavior; later fixtures exercise valid and invalid fields together.
type FieldError={field:string;rule:string};
function solve(value:string):string[] { const row=JSON.parse(value) as Record<string,unknown>; const errors:string[]=[]; if(typeof row.email!=="string" || row.email.trim()==="") errors.push("email:required"); return errors; }
A complete implementation for the first scenario; trace its input before editing.