Zod - 类型“typeof import(.../node_modules/zod/lib/external)”上不存在属性“infer”

UNl*_*nel 7 javascript typescript zod

我收到打字稿错误:

Property 'infer' does not exist on type 'typeof import(.../node_modules/zod/lib/external)

在代码上: const CampaignForm = z.infer<typeof CampaignSchema>;

查看文档和node_modules,该属性就在那里。

UNl*_*nel 22

问题是使用const而不是type.

预期的type CampaignForm = z.infer<typeof CampaignSchema>;

实际的const CampaignForm = z.infer<typeof CampaignSchema>;

该错误具有误导性。