From 559a8cba5814194b679de5beb3a66d5bda87e25b Mon Sep 17 00:00:00 2001 From: Mauro Erta Date: Mon, 29 Apr 2024 18:12:09 +0200 Subject: [PATCH] fix(FormField): added a utility type to fix some type errors (#81) Co-authored-by: Mauro Erta Co-authored-by: Benjamin Canac --- src/runtime/composables/useFormField.ts | 7 +++---- src/runtime/types/form.ts | 4 ++-- src/runtime/types/utils.d.ts | 4 ++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/runtime/composables/useFormField.ts b/src/runtime/composables/useFormField.ts index d5dcd57b..3f138499 100644 --- a/src/runtime/composables/useFormField.ts +++ b/src/runtime/composables/useFormField.ts @@ -1,14 +1,13 @@ import { inject, ref, computed } from 'vue' import { type UseEventBusReturn, useDebounceFn } from '@vueuse/core' import type { FormEvent, FormInputEvents, FormFieldInjectedOptions, FormInjectedOptions } from '#ui/types/form' +import type { GetObjectField } from '#ui/types/utils' type Props = { id?: string name?: string - // @ts-expect-error FIXME: TS doesn't like this - size?: T['size'] - // @ts-expect-error FIXME: TS doesn't like this - color?: T['color'] + size?: GetObjectField + color?: GetObjectField eagerValidation?: boolean legend?: string disabled?: boolean diff --git a/src/runtime/types/form.ts b/src/runtime/types/form.ts index 056cb53a..f87dee68 100644 --- a/src/runtime/types/form.ts +++ b/src/runtime/types/form.ts @@ -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 { validate (opts?: { name: string | string[], silent?: false, nested?: boolean }): Promise @@ -71,8 +72,7 @@ export interface FormInjectedOptions { export interface FormFieldInjectedOptions { id: Ref name: ComputedRef - // @ts-expect-error FIXME: TS doesn't like this - size: ComputedRef + size: ComputedRef> error: ComputedRef eagerValidation: ComputedRef validateOnInputDelay: ComputedRef diff --git a/src/runtime/types/utils.d.ts b/src/runtime/types/utils.d.ts index 80aadc50..2257721d 100644 --- a/src/runtime/types/utils.d.ts +++ b/src/runtime/types/utils.d.ts @@ -4,3 +4,7 @@ export type DeepPartial = Partial<{ export type DynamicSlots = Record & (Slot extends string ? Record : Record) + +export type GetObjectField = MaybeObject extends Record + ? MaybeObject[Key] + : never