toZod 是一个实用程序,用于定义与 TypeScript 类型一致的 Zod 模式。它基本上通过为 toZod 提供一个类型来为您的模式提供自动建议的属性。如果您的类型发生变化,它会显示一条错误消息,通知您需要相应地更改架构。
我过去在类型上成功使用了 toZod,但现在我正尝试在使用 TRPC 的 inferRouterOutput 推理助手 推断出的类型上使用 toZod。我遇到了某种“剥离”错误,当我按 ctrl + space 时,我的类型都没有出现,就像我通常会得到的那样。
这是我目前拥有的代码:
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();
将鼠标悬停在“TreeSchema”上时,我收到一条显示变量的消息,然后显示类型错误消息。我在错误消息中看到“剥离”一词,所以我想知道这是否是问题所在的线索?
这里是变量
const treeSchema: z.ZodArray
; 更多属性等.... }, "strip", z.ZodTypeAny, { ...; },{ ...; }>, "许多">
这里是所有的错误
Type 'ZodArray
, "many">' is 不可分配给类型 'ZodArray ; }, "strip", ZodTypeAny, Product, Product>>; ... 31 更多 ...; competitorReference: ZodNullable<...> ...'.
类型“ZodObject<{}, "strip", ZodTypeAny, {}, {}>”不可分配 输入'ZodObject<{ product: ZodNullable
; }, "strip", ZodTypeAny, Product, Product>>; ... 31 更多的 ...;竞争对手参考:ZodNullable<...> | ZodNull...'.
类型“{}”缺少类型“{ product: ZodNullable
; 中的以下属性}, "strip", ZodTypeAny, Product, Product>>; ... 31 更多的 ...;竞争对手参考:ZodNullable<...> | ZodNullable<...>; }': product, supplierData, models, existingDrawings, and 29 more.