Deviopath › TypeScript

Validate a Signup Form

Medium · Utility Types

Write validateSignup(form: SignupForm): FormErrors where FormErrors = Partial<Record<keyof SignupForm, string>>.

Only include a field when it is invalid:

- username shorter than 3 characters: "Username must be at least 3 characters"

- email without "@": "Email must contain @"

- password shorter than 8 characters: "Password must be at least 8 characters"

A valid form returns {}.

Next: Door State Machine