From 5c889d4cbdd33e34ef409c3f5601d263ccef0c6b Mon Sep 17 00:00:00 2001 From: tankosinn Date: Mon, 19 May 2025 18:17:54 +0300 Subject: [PATCH 1/2] fix(Form): conditionally type form data via `transform` prop --- src/runtime/components/Form.vue | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/runtime/components/Form.vue b/src/runtime/components/Form.vue index c5f4d5dc87..462d7412a9 100644 --- a/src/runtime/components/Form.vue +++ b/src/runtime/components/Form.vue @@ -7,7 +7,9 @@ import type { ComponentConfig } from '../types/utils' type FormConfig = ComponentConfig -export interface FormProps { +type FormData = T extends true ? InferOutput : InferInput + +export interface FormProps { id?: string | number /** Schema to validate the form state. Supports Standard Schema objects, Yup, Joi, and Superstructs. */ schema?: S @@ -35,7 +37,7 @@ export interface FormProps { * If true, schema transformations will be applied to the state on submit. * @defaultValue `true` */ - transform?: boolean + transform?: T /** * If true, this form will attach to its parent Form (if any) and validate at the same time. @@ -50,11 +52,11 @@ export interface FormProps { */ loadingAuto?: boolean class?: any - onSubmit?: ((event: FormSubmitEvent>) => void | Promise) | (() => void | Promise) + onSubmit?: ((event: FormSubmitEvent>) => void | Promise) | (() => void | Promise) } -export interface FormEmits { - (e: 'submit', payload: FormSubmitEvent>): void +export interface FormEmits { + (e: 'submit', payload: FormSubmitEvent>): void (e: 'error', payload: FormErrorEvent): void } @@ -63,7 +65,7 @@ export interface FormSlots { } -