ciscoheat / sveltekit-superforms

Making SvelteKit forms a pleasure to use!
https://superforms.rocks
MIT License
2.26k stars 66 forks source link

Make type `SuperFormData` importable #478

Closed PeytonHanel closed 2 months ago

PeytonHanel commented 2 months ago

Is your feature request related to a problem? Please describe. Passing a form to a component as a prop could have a better Typescript experience.

// +page.svelte
<script lang='ts'>
  import { superForm } from "sveltekit-superforms"
  export let data
  const { form } = superForm(data.form)
</script>
<MyComponent {form} />
// MyComponent.svelte
<script lang='ts'>
  // what I wish I could do
  export let form: SuperFormData<Infer<typeof schema>>

  // what I have to do
  export let form: SuperForm<Infer<typeof schema>>['form']
</script>

There could be a nice utility type possibly that acts like this export let form: SuperFormData<typeof schema>

Describe the solution you'd like See above

Describe alternatives you've considered I could just do this which I also don't want to do

<script lang='ts'>
  // just accept data.form and call superForm here instead
  export let formData: PageData['form']
  const {form} = superForm(data.form)
</script>
ciscoheat commented 2 months ago

I'll export SuperFormData and SuperFormErrors in the next release.

ciscoheat commented 2 months ago

Added in 2.18.0