fix(forms): support generic unions in signal form schemas#67304
Open
alxhub wants to merge 1 commit intoangular:mainfrom
Open
fix(forms): support generic unions in signal form schemas#67304alxhub wants to merge 1 commit intoangular:mainfrom
alxhub wants to merge 1 commit intoangular:mainfrom
Conversation
This commit resolves an issue where using an uninstantiated generic type parameter in a signal form model caused TypeScript compilation failures due to distributive conditional types (angular#66596). The previous attempt to fix this issue by tuple-wrapping everything caused another bug (angular#65535) that prevented property access on generic unions. This commit balances the need to resolve nested generic property access while handling infinitely recursive generic structures without depth errors. What changed and why: - Base State Wrappers: Tuple wrappers (`[TModel] extends [AbstractControl]`) are applied to `FieldTreeBase` to safely defer generic evaluation. This prevents primitive unions (like `boolean`) from incorrectly evaluating to `never`. - Naked Map Over Children: Object subfield checks (`TModel extends Record`) are re-evaluated as purely naked conditionals. Eager distribution over generics allows users to directly access shared properties of unresolved union types. - Array Interface Deflection: `ReadonlyArrayLike<T>` generic abstraction is redefined as an explicit `interface` instead of a mapped `Pick` type alias. This optimally intercepts TypeScript from eagerly evaluating infinitely recursive array structures (e.g. `RecursiveType = (number | RecursiveType)[]`). - Overloaded Context Methods: `FieldNodeContext.stateOf` and `fieldTreeOf` are defined as explicitly overloaded class methods and lexically bound (`this`) in the constructor. These changes are required to safely align the runtime bindings with the tautological conditionals implemented in the `RootFieldContext` interface structure. Fixes angular#65535
d878d21 to
74d52e0
Compare
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.
This commit resolves an issue where using an uninstantiated generic type parameter in a signal form model caused TypeScript compilation failures due to distributive conditional types (#66596). The previous attempt to fix this issue by tuple-wrapping everything caused another bug (#65535) that prevented property access on generic unions.
This commit balances the need to resolve nested generic property access while handling infinitely recursive generic structures without depth errors.
What changed and why:
[TModel] extends [AbstractControl]) are applied toFieldTreeBaseto safely defer generic evaluation. This prevents primitive unions (likeboolean) from incorrectly evaluating tonever.TModel extends Record) are re-evaluated as purely naked conditionals. Eager distribution over generics allows users to directly access shared properties of unresolved union types.ReadonlyArrayLike<T>generic abstraction is redefined as an explicitinterfaceinstead of a mappedPicktype alias. This optimally intercepts TypeScript from eagerly evaluating infinitely recursive array structures (e.g.RecursiveType = (number | RecursiveType)[]).FieldNodeContext.stateOfandfieldTreeOfare defined as explicitly overloaded class methods and lexically bound (this) in the constructor. These changes are required to safely align the runtime bindings with the tautological conditionals implemented in theRootFieldContextinterface structure.Fixes #65535