The plan is to develop an app with a hierarchic data structure. To validate the data, Zod is used to create a recursive structure. The base category schema is defined with properties for name, percent, amount, and percentages. The category type is defined as the base category schema with an additional property for categories, which is an array of the same category type. The category schema is then extended to include an array of categories using Zod's lazy function. This allows the category schema to reference itself before it's fully initialized. The category schema type is then defined as the inferred type of the category schema. A test data object is created to demonstrate the hierarchical structure, with categories and subcategories. The test data object includes properties for amount, name, categories, and percentages. The percentages property is an array of objects with name and percent properties.
dev.to
dev.to
