chore: fix lint and typecheck issues

This commit is contained in:
xingyu4j
2026-03-13 20:57:52 +08:00
parent 771277d5d9
commit a850d426ef
26 changed files with 306 additions and 155 deletions

View File

@@ -57,8 +57,10 @@ describe('loadScript', () => {
appendSpy.mockRestore();
expect(capturedScript).toBeTruthy();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
capturedScript!.dispatchEvent(new Event('error'));
if (!capturedScript) {
throw new Error('Expected the captured script element to exist');
}
capturedScript.dispatchEvent(new Event('error'));
await expect(promise).rejects.toThrow('Failed to load script: error.js');
});

View File

@@ -1,4 +1,3 @@
// eslint-disable-next-line vue/prefer-import-from-vue
import { isFunction, isObject, isString } from '@vue/shared';
/**

View File

@@ -36,9 +36,11 @@ export default function useDependencies(
const values = useFormValues();
const formRenderProps = injectRenderFormProps();
const formApi = formRenderProps.form;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const formApi = formRenderProps.form!;
if (!formApi) {
throw new Error('Form api is required in useDependencies');
}
if (!values) {
throw new Error('useDependencies should be used within <VbenForm>');

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { ZodType } from 'zod';
import type { FormSchema, MaybeComponentProps } from '../types';
import type { FormActions, FormSchema, MaybeComponentProps } from '../types';
import { computed, nextTick, onUnmounted, useTemplateRef, watch } from 'vue';
@@ -63,6 +63,14 @@ const formApi = formRenderProps.form;
const compact = computed(() => formRenderProps.compact);
const isInValid = computed(() => errors.value?.length > 0);
function getFormApi(): FormActions {
if (!formApi) {
throw new Error('Form api is required in <FormField />');
}
return formApi;
}
const FieldComponent = computed(() => {
const finalComponent = isString(component)
? componentMap.value[component]
@@ -156,7 +164,7 @@ const fieldRules = computed(() => {
const computedProps = computed(() => {
const finalComponentProps = isFunction(componentProps)
? componentProps(values.value, formApi!)
? componentProps(values.value, getFormApi())
: componentProps;
return {
@@ -186,7 +194,7 @@ const customContentRender = computed(() => {
if (!isFunction(renderComponentContent)) {
return {};
}
return renderComponentContent(values.value, formApi!);
return renderComponentContent(values.value, getFormApi());
});
const renderContentKey = computed(() => {