Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/forms/src/form_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ 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> :
// 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> :
// Optional FormArray containers.
Expand Down
9 changes: 8 additions & 1 deletion packages/forms/src/model/form_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,14 @@ export const isFormGroup = (control: unknown): control is FormGroup => control i
* @publicApi
*/
export class FormRecord<TControl extends AbstractControl = AbstractControl> extends
FormGroup<{[key: string]: TControl}> {}
FormGroup<{[key: string]: TControl}> {
/**
* Internal marker to differentiate `FormRecord` from `FormGroup` type.
*
* This is for internal Angular usage to support typed forms; do not directly use it.
*/
private readonly formRecordBrand!: unknown;
}

export interface FormRecord<TControl> {
/**
Expand Down