toZod is a utility for defining Zod schemas that agree with a TypeScript type. It basically gives you auto-suggested properties for your schema by supplying toZod with a type. If your type ever changes, it will show an error notifying you that you need to change your schema accordingly.
I have successfully used toZod on types in the past, but now I'm trying to use toZod on a type that was inferred using TRPC's inferRouterOutput inference helper. I'm getting some kind of 'strip' error and none of my types are appearing when I press ctrl + space like I would usually get.
This is the code I currently have:
type RouterOutput = inferRouterOutputs<AppRouter>;
type DefinitionTree = RouterOutput["product"]["getProductDefinitionTree"];
const treeSchema: toZod<DefinitionTree> = z.object({
//properties should be showing up as suggestions (via ctrl + space)
}).array();
Upon hovering my mouse over 'TreeSchema', I get a message that shows the variable and then shows a type error message. I see the word "strip" in the error message so I'm wondering if that is a clue to what the issue is?
Here is the variable
const treeSchema: z.ZodArray<z.ZodObject<{
product: z.ZodNullable<z.ZodObject<{
id: z.ZodString;
name: z.ZodNullable<z.ZodString>;
*more properties etc....*
}, "strip", z.ZodTypeAny, {
...;
},{
...;
}>, "many">
Here are all of the errors
Type 'ZodArray<ZodObject<{}, "strip", ZodTypeAny, {}, {}>, "many">' is
not assignable to type 'ZodArray<ZodObject<{ product:
ZodNullable<ZodObject<{ id: ZodString; name: ZodNullable<ZodString>;
description: ZodNullable<ZodString>; createdById:
ZodNullable<ZodString>; ... 4 more ...; updatedAt: ZodNullable<...>;
}, "strip", ZodTypeAny, Product, Product>>; ... 31 more ...;
competitorReference: ZodNullable<...> ...'.
Type 'ZodObject<{}, "strip", ZodTypeAny, {}, {}>' is not assignable
to type 'ZodObject<{ product: ZodNullable<ZodObject<{ id: ZodString;
name: ZodNullable<ZodString>; description: ZodNullable<ZodString>;
createdById: ZodNullable<ZodString>; ... 4 more ...; updatedAt:
ZodNullable<...>; }, "strip", ZodTypeAny, Product, Product>>; ... 31
more ...; competitorReference: ZodNullable<...> | ZodNull...'.
Type '{}' is missing the following properties from type '{ product: ZodNullable<ZodObject<{ id: ZodString; name:
ZodNullable<ZodString>; description: ZodNullable<ZodString>;
createdById: ZodNullable<ZodString>; ... 4 more ...; updatedAt:
ZodNullable<...>; }, "strip", ZodTypeAny, Product, Product>>; ... 31
more ...; competitorReference: ZodNullable<...> | ZodNullable<...>;
}': product, supplierData, models, existingDrawings, and 29 more.