logaretm / vee-validate

āœ… Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.79k stars 1.26k forks source link

export Component Props (e.g. for `Form` component) #4892

Open beselig opened 1 week ago

beselig commented 1 week ago

Is your feature request related to a problem? I am building a component library in which I am implementing pre-styled wrappers for Field and Form components.

I expected that I would be able to import the type of the Form component's props, so that I could just do this:

<template>
  <Form
    class="whatever"
    v-bind="props"
  >
    <slot />
  </Form>
</template>

<script setup lang="ts">
import type { FormProps } from "vee-validate"

const props = defineProps<FormProps>()
</script>

For the Field component, I am aware that I can build a custom input myself, using defineField and such, to do exactly what Field does under the hood. But for Form I am sure that it would not be feasible. Even for Field I don't see why I should have to do that.

If someone can point me to another way of achieving what I am trying to achieve, or tell me why what I am doing should be avoided or there is a simpler way and I am overengineering this, feel free to call me on my bs. šŸ˜„

Otherwise I guess the obvious solution is to add an export infront of the Prop type declarations inside components Form, Field and other customizable components. After glancing over the implementations, I believe that should do the trick.

Hope all this makes sense or someone can tell my why it doesn't. Cheers šŸ‘‹šŸ¼

logaretm commented 3 days ago

Sounds reasonable, but our Form types are actually runtime types and not a typescript interface so it may have some differences when Vue's compiler attempts to reverse generate the runtime types, for example you lose the defaults then.

It might be possible to expose as an object rather than a type.