diff --git a/src/composables/use-link-field.ts b/src/composables/use-link-field.ts index f95421f22..9a7c2fc81 100644 --- a/src/composables/use-link-field.ts +++ b/src/composables/use-link-field.ts @@ -1,11 +1,11 @@ -import { ComponentInstance } from '../utils'; -import { watch, inject } from 'vue'; +import { watch, inject, InjectionKey } from 'vue'; +import type { FieldProvide } from '../field/types'; export const FORM_KEY = Symbol('van-form'); -export const FIELD_KEY = Symbol('van-field'); +export const FIELD_KEY: InjectionKey = Symbol('van-field'); export function useLinkField(getValue: () => unknown) { - const field = inject(FIELD_KEY, null) as ComponentInstance | null; + const field = inject(FIELD_KEY, null); if (field && !field.childFieldValue.value) { field.childFieldValue.value = getValue; diff --git a/src/field/types.ts b/src/field/types.ts index 09fdc6ff3..2bf9d2027 100644 --- a/src/field/types.ts +++ b/src/field/types.ts @@ -1,3 +1,5 @@ +import type { Ref } from 'vue'; + export type FieldType = | 'tel' | 'text' @@ -37,6 +39,12 @@ export type FieldRule = { formatter?: (value: any, rule: FieldRule) => string; }; +export type FieldProvide = { + childFieldValue: Ref<(() => unknown) | undefined>; + resetValidation: () => void; + validateWithTrigger: (trigger: FieldValidateTrigger) => void; +}; + declare global { interface EventTarget { composing?: boolean;