diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index 2317fb2b9..66ec37b14 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -662,16 +662,18 @@ export type DerivedFormState< * The error array for the form itself. */ errors: Array< - | UnwrapFormValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormAsyncValidateOrFn + NonNullable< + | UnwrapFormValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormAsyncValidateOrFn + > > /** * A boolean indicating if any of the form fields are currently validating. @@ -1253,14 +1255,16 @@ export class FormApi< ) { errors = Object.values(currBaseStore.errorMap).reduce< Array< - | UnwrapFormValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormAsyncValidateOrFn + NonNullable< + | UnwrapFormValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormAsyncValidateOrFn + > > >((prev, curr) => { if (curr === undefined) return prev @@ -2662,16 +2666,18 @@ export class FormApi< getAllErrors = (): { form: { errors: Array< - | UnwrapFormValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormValidateOrFn - | UnwrapFormAsyncValidateOrFn - | UnwrapFormAsyncValidateOrFn + NonNullable< + | UnwrapFormValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormValidateOrFn + | UnwrapFormAsyncValidateOrFn + | UnwrapFormAsyncValidateOrFn + > > errorMap: ValidationErrorMap< UnwrapFormValidateOrFn, diff --git a/packages/form-core/tests/FieldApi.test-d.ts b/packages/form-core/tests/FieldApi.test-d.ts index 838b5c4e1..6c98ed538 100644 --- a/packages/form-core/tests/FieldApi.test-d.ts +++ b/packages/form-core/tests/FieldApi.test-d.ts @@ -238,7 +238,7 @@ it('should have the correct types returned from form validators in array', () => }, } as const) - expectTypeOf(form.state.errors).toEqualTypeOf>() + expectTypeOf(form.state.errors).toEqualTypeOf>() }) it('should handle "fields" return types added to the field\'s errorMap itself', () => { diff --git a/packages/form-core/tests/FormApi.test-d.ts b/packages/form-core/tests/FormApi.test-d.ts index 1d2554a6e..ebf6813ad 100644 --- a/packages/form-core/tests/FormApi.test-d.ts +++ b/packages/form-core/tests/FormApi.test-d.ts @@ -48,7 +48,6 @@ it('should return all errors matching the right type from getAllErrors', () => { | 'onSubmitAsync' | { onBlur: true; onBlurNumber: number } | 'onBlurAsync' - | undefined )[] >() @@ -365,14 +364,7 @@ it('should extract the form error type from a global form error', () => { >() expectTypeOf(form.state.errors).toEqualTypeOf< - ( - | 'onMount' - | 'onChange' - | 'onChangeAsync' - | 'onBlur' - | 'onBlurAsync' - | undefined - )[] + ('onMount' | 'onChange' | 'onChangeAsync' | 'onBlur' | 'onBlurAsync')[] > }) diff --git a/packages/form-core/tests/formOptions.test-d.ts b/packages/form-core/tests/formOptions.test-d.ts index eb7b39a45..fd8089549 100644 --- a/packages/form-core/tests/formOptions.test-d.ts +++ b/packages/form-core/tests/formOptions.test-d.ts @@ -286,9 +286,7 @@ describe('formOptions', () => { const form = new FormApi(formOpts) - expectTypeOf(form.state.errors).toEqualTypeOf< - ('I just need an error' | undefined)[] - >() + expectTypeOf(form.state.errors).toEqualTypeOf<'I just need an error'[]>() const form2 = new FormApi({ ...formOpts, @@ -302,9 +300,7 @@ describe('formOptions', () => { }, }) - expectTypeOf(form2.state.errors).toEqualTypeOf< - (undefined | 'Too short!')[] - >() + expectTypeOf(form2.state.errors).toEqualTypeOf<'Too short!'[]>() const form3 = new FormApi({ ...formOpts, @@ -320,7 +316,7 @@ describe('formOptions', () => { }) expectTypeOf(form3.state.errors).toEqualTypeOf< - (undefined | 'Too short!' | 'I just need an error')[] + ('Too short!' | 'I just need an error')[] >() }) })