Skip to content

Commit 4dfe5b6

Browse files
crisbetoAndrewKushnir
authored andcommitted
fix(forms): work around TypeScript 5.7 issue (#58731)
Adjusts the return type of `FormBuilder.group` to work around microsoft/TypeScript#60506. PR Close #58731
1 parent e4dc7f1 commit 4dfe5b6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

goldens/public-api/forms/index.api.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ export class FormBuilder {
308308
control<T>(formState: T | FormControlState<T>, opts: FormControlOptions, asyncValidator: AsyncValidatorFn | AsyncValidatorFn[]): FormControl<T | null>;
309309
// (undocumented)
310310
control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | FormControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T | null>;
311-
group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroup<{
312-
[K in keyof T]: ɵElement<T[K], null>;
313-
}>;
311+
group<T extends {}>(controls: T, options?: AbstractControlOptions | null): ɵNullableFormGroup<T>;
314312
// @deprecated
315313
group(controls: {
316314
[key: string]: any;
@@ -768,9 +766,7 @@ export class NgSelectOption implements OnDestroy {
768766
export abstract class NonNullableFormBuilder {
769767
abstract array<T>(controls: Array<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormArrayElement<T, never>>;
770768
abstract control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T>;
771-
abstract group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroup<{
772-
[K in keyof T]: ɵElement<T[K], never>;
773-
}>;
769+
abstract group<T extends {}>(controls: T, options?: AbstractControlOptions | null): ɵNonNullableFormGroup<T>;
774770
abstract record<T>(controls: {
775771
[key: string]: T;
776772
}, options?: AbstractControlOptions | null): FormRecordElement<T, never>>;

packages/forms/src/form_builder.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ interface PermissiveAbstractControlOptions extends Omit<AbstractControlOptions,
5353
updateOn?: string;
5454
}
5555

56+
// Note: these two types have been extracted into type aliases to work around a .d.ts generation
57+
// issue in TypeScript 5.7. See: https://github.com/Microsoft/TypeScript/issues/60506. The types
58+
// have to be exported for the workaround to work.
59+
/** Group of nullable form controls. */
60+
export type ɵNullableFormGroup<T> = FormGroup<{[K in keyof T]: ɵElement<T[K], null>}>;
61+
62+
/** Group of non-nullable form controls. */
63+
export type ɵNonNullableFormGroup<T> = FormGroup<{[K in keyof T]: ɵElement<T[K], never>}>;
64+
5665
/**
5766
* ControlConfig<T> is a tuple containing a value of type T, plus optional validators and async
5867
* validators.
@@ -194,10 +203,7 @@ export class FormBuilder {
194203
* * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur'
195204
* | submit').
196205
*/
197-
group<T extends {}>(
198-
controls: T,
199-
options?: AbstractControlOptions | null,
200-
): FormGroup<{[K in keyof T]: ɵElement<T[K], null>}>;
206+
group<T extends {}>(controls: T, options?: AbstractControlOptions | null): ɵNullableFormGroup<T>;
201207

202208
/**
203209
* @description
@@ -418,7 +424,7 @@ export abstract class NonNullableFormBuilder {
418424
abstract group<T extends {}>(
419425
controls: T,
420426
options?: AbstractControlOptions | null,
421-
): FormGroup<{[K in keyof T]: ɵElement<T[K], never>}>;
427+
): ɵNonNullableFormGroup<T>;
422428

423429
/**
424430
* Similar to `FormBuilder#record`, except any implicitly constructed `FormControl`

0 commit comments

Comments
 (0)