I have a type that's being "layered" from data in several json files.
I am reading a json, parsing it into my type (an object with optional fields, some fields have literal types), then layering the new object over the old one with a destruct-restruct ({ ...previous, ...next }) in a reducer mapper function for this type. Repeats for every specified file.
If the value doesn't match the type, I want to print a human-readable error like Source: ${source}. Issue: Wrong value in ${parameter}, should be ${expectedType} at runtime.
What would be a "better" pattern here? Should I maybe transition from "type & namespace" to using classes and class constructor definition?