fix(FormField): added a utility type to fix some type errors (#81)

Co-authored-by: Mauro Erta <mauro.erta@sap.com>
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Mauro Erta
2024-04-29 18:12:09 +02:00
committed by GitHub
parent 46bd407b91
commit 559a8cba58
3 changed files with 9 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ import type { ZodSchema } from 'zod'
import type { Schema as JoiSchema } from 'joi'
import type { ObjectSchema as YupObjectSchema } from 'yup'
import type { ObjectSchemaAsync as ValibotObjectSchema } from 'valibot'
import type { GetObjectField } from './utils'
export interface Form<T> {
validate (opts?: { name: string | string[], silent?: false, nested?: boolean }): Promise<T | false>
@@ -71,8 +72,7 @@ export interface FormInjectedOptions {
export interface FormFieldInjectedOptions<T> {
id: Ref<string | undefined>
name: ComputedRef<string | undefined>
// @ts-expect-error FIXME: TS doesn't like this
size: ComputedRef<T['size']>
size: ComputedRef<GetObjectField<T, 'size'>>
error: ComputedRef<string | boolean | undefined>
eagerValidation: ComputedRef<boolean | undefined>
validateOnInputDelay: ComputedRef<number | undefined>

View File

@@ -4,3 +4,7 @@ export type DeepPartial<T> = Partial<{
export type DynamicSlots<T extends { slot?: string }, SlotProps, Slot = T['slot']> =
Record<string, SlotProps> & (Slot extends string ? Record<Slot, SlotProps> : Record<string, never>)
export type GetObjectField<MaybeObject, Key extends string> = MaybeObject extends Record<string, any>
? MaybeObject[Key]
: never