Type for a Zod Type? #3318
-
Hi guys, I am exploring using Zod for dynamic forms. What is the correct type to assign to declare that a key value should be a Zod schema property value? interface AppInputInterface {
label: string;
controlType: "text" | "select";
type: z.ZodAny; // <----------- What is the correct type?
}
interface AppFormInterface {
name: string;
schema: {
[key: string]: AppInputInterface;
};
}
const createOrgFormSchema: AppFormInterface = {
name: "create_org",
schema: {
organization_name: {
label: "Organization name",
type: z.string(), // <----------- "type" should be any Zod schema property value
controlType: "text",
},
country: {
label: "Country",
controlType: "select",
type: z.string(), // <----------- "type" should be any Zod schema property value
},
},
}; |
Beta Was this translation helpful? Give feedback.
Answered by
JacobWeisenburger
Mar 11, 2024
Replies: 1 comment
-
Is this what you are looking for? interface AppInputInterface {
label: string
controlType: "text" | "select"
type: z.ZodTypeAny
type: z.Schema // also works
}
interface AppFormInterface {
name: string
schema: {
[ key: string ]: AppInputInterface
}
}
const createOrgFormSchema: AppFormInterface = {
name: "create_org",
schema: {
organization_name: {
label: "Organization name",
type: z.string(), // works
controlType: "text",
},
country: {
label: "Country",
controlType: "select",
type: z.string(), // works
},
},
} If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JacobWeisenburger
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this what you are looking for?
If you found my answer satis…