From a8f268cfc00683e83aceb30e1a3e719716897b93 Mon Sep 17 00:00:00 2001 From: Isaac Hunja Date: Fri, 6 Mar 2026 07:51:33 +0300 Subject: [PATCH] fix(form-core): exclude undefined from FormState errors type The runtime code filters out undefined values from the errorMap when building the errors array (via .filter(val => val !== undefined)), but the type definition allowed undefined in the union. This forced consumers to add unnecessary runtime undefined checks when iterating over errors. Wrapping the error union with NonNullable aligns the type with the actual runtime behavior. Fixes #2022 --- packages/form-core/src/FormApi.ts | 44 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index d78c39a8a..ab3712681 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -644,16 +644,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. @@ -2642,16 +2644,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,