import type { PropOptions, PropType } from 'vue'; import { z } from 'zod'; /** * @summary Easily define & validate vue props, improve error messages drastically * * @description * This augments/replaces Vue’s props entirely, including the need to add prop.validator * by using zod and therefore actually prints errors to the console that can help developers * rather than the non-distinct vue-warn message about a validator failing for a component. * * ## Known limitations: * * 1. Deeply defined defaults are only applied when manually `schema.safeParse`-ing the data (only top-level defaults are possible to transform to Vue) * 2. `z.safeParse()` fails for type: `z.function()` if we specify the default, without explicitly chaining * `optional()` on the function type. (See {@link https://github.com/colinhacks/zod/issues/647}) * However, it is inconsequential for Vue prop validation, as Vue doesn’t execute the `validator` if the prop is not passed/undefined. * * @example * // KtUserMenu.vue * export default defineComponent({ * name: 'KtUserMenu', * props: makeProps(KottiUserMenu.propsSchema) * setup(props) * }) * * // types.ts * export namespace KottiUserMenu { * export const propsSchema = z.object({ * // ... * }) * type Props = z.input * type PropsInternal = z.output * } */ export declare const makeProps: >(propsSchema: PROPS_SCHEMA) => { [PROP_NAME in keyof PROPS_SCHEMA["shape"]]: Omit & { default: undefined extends z.input[PROP_NAME] ? () => z.output[PROP_NAME] : undefined; required: undefined extends z.input[PROP_NAME] ? false : true; type: PropType[PROP_NAME]>; }; };