mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(forms): fix FormRecord type inference (#50750)
Updates type inference in `ɵElement` to make `FormRecord` take precedence over `FormGroup` PR Close #50750
This commit is contained in:
parent
9762b24b5e
commit
18b6f3339f
1 changed files with 16 additions and 12 deletions
|
|
@ -75,24 +75,28 @@ export type ɵElement<T, N extends null> =
|
|||
// through the distributive conditional type. This is the officially recommended solution:
|
||||
// https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
|
||||
//
|
||||
// Note: Because `FormRecord` implementation extends `FormGroup`, it must be checked BEFORE `FormGroup`
|
||||
// in the following clauses (otherwise it may incorrectly be inferred to `FormGroup`).
|
||||
//
|
||||
//
|
||||
// Identify FormControl container types.
|
||||
[T] extends [FormControl<infer U>]
|
||||
? FormControl<U>
|
||||
: // Or FormControl containers that are optional in their parent group.
|
||||
[T] extends [FormControl<infer U> | undefined]
|
||||
? FormControl<U>
|
||||
: // FormGroup containers.
|
||||
[T] extends [FormGroup<infer U>]
|
||||
? FormGroup<U>
|
||||
: // Optional FormGroup containers.
|
||||
[T] extends [FormGroup<infer U> | undefined]
|
||||
? FormGroup<U>
|
||||
: // FormRecord containers.
|
||||
[T] extends [FormRecord<infer U>]
|
||||
? FormRecord<U>
|
||||
: // Optional FormRecord containers.
|
||||
[T] extends [FormRecord<infer U> | undefined]
|
||||
? FormRecord<U>
|
||||
: // FormRecord containers.
|
||||
[T] extends [FormRecord<infer U>]
|
||||
? FormRecord<U>
|
||||
: // Optional FormRecord containers.
|
||||
[T] extends [FormRecord<infer U> | undefined]
|
||||
? FormRecord<U>
|
||||
: // FormGroup containers.
|
||||
[T] extends [FormGroup<infer U>]
|
||||
? FormGroup<U>
|
||||
: // Optional FormGroup containers.
|
||||
[T] extends [FormGroup<infer U> | undefined]
|
||||
? FormGroup<U>
|
||||
: // FormArray containers.
|
||||
[T] extends [FormArray<infer U>]
|
||||
? FormArray<U>
|
||||
|
|
|
|||
Loading…
Reference in a new issue