feat(froms): add submit method to field state#66895
Open
mmalerba wants to merge 3 commits intoangular:mainfrom
Open
feat(froms): add submit method to field state#66895mmalerba wants to merge 3 commits intoangular:mainfrom
mmalerba wants to merge 3 commits intoangular:mainfrom
Conversation
Changes the `submit` function from a separately imported function to a method on the `FieldState`
The `action` and `onInvalid` handlers now recevie two pieces of information: 1. The form that is being submitted 2. The specific field that the submit was triggered on
leonsenft
requested changes
Feb 3, 2026
| this.parent?.updateValueAndValidity({sourceControl: this} as any), | ||
| ); | ||
| this.fieldState = this.fieldTree(); | ||
| this.fieldState = this.fieldTree() as FieldState<T>; |
Contributor
There was a problem hiding this comment.
What caused this cast to become necessary?
Contributor
Author
There was a problem hiding this comment.
I'm honestly not sure, here's what gemini told me:
The
submitmethod introduced a circular dependency betweenFieldStateandFieldTreethat forced TypeScript to be stricter about structural compatibility.Here is the breakdown:
- The New Cycle: The commit added
submit(options: FormSubmitOptions<T>)toFieldState.FormSubmitOptionshas a propertyaction: (form: FieldTree<T>) => .... This creates a cycle:FieldState→FormSubmitOptions→FieldTree→FieldState.- Structural Incompatibility:
FieldTree<T>is a conditional type. IfTis anAbstractControl, it returnsCompatFieldState<T>(which isFieldState<ValueType>). However,SignalFormControltyped itsfieldStateproperty asFieldState<T>(which would beFieldState<AbstractControl>).- Why it broke: Before the
submitmethod, TypeScript likely didn't fully resolve the conditional type mismatch or treated the types as structurally compatible enough. The newsubmitmethod, with its function argument takingFieldTree<T>, made the types structurally distinct and incompatible (due to contravariance in theactioncallback), exposing the underlying issue thatFieldState<AbstractControl>is not the same asFieldState<ValueType>.
If that is to be believed, it sounds like the types may not have been quite right to begin with and this just exposed the issue
@kirjs do you understand why I need this cast now?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(froms): add submit method to field state
Changes the
submitfunction from a separately imported function to amethod on the `FieldState
feat(forms): add field param to submit action and onInvalid
The
actionandonInvalidhandlers now recevie two pieces ofinformation: