Evolving form data and typesafety .
I'm building an app where clients submit forms and professionals can subscribe to them.
The challenge: Each service (cleaning, plumbing, etc.) has its own unique form structure. Professionals can subscribe to specific services and filter based on form fields (e.g., "only show me residential cleaning jobs").
The main problem: When service forms evolve over time (adding/removing/modifying fields), I need to preserve old submissions exactly as they were submitted. However, this breaks TypeScript/Zod type safety.
For example:
// Original cleaning form type
// Updated cleaning form type (removed a field field)
Now TypeScript/Zod will complains when accessing old submissions in my database as they dont match updated types
How do you handle this type safety problem when dealing with historical data that doesn't match your current types? Looking for patterns or approaches that maintain type safety across different versions of the same form.
1 Reply
Cant find anybody having my issue so I must be doing something wrong or thinking about if the wrong way.
The only way i came up with is adding versioning to my schemas (in my codebase) everytime my schema changes but then my code will become messy real quick