Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cebf255

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(forms): work around another TypeScript 5.7 issue (#58782)
Reworks the changes from #58731, because they didn't cover all use cases. PR Close #58782
1 parent 7eeae9f commit cebf255

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +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): ɵNullableFormGroup<T>;
311+
group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroupNullableFormControls<T>>;
312312
// @deprecated
313313
group(controls: {
314314
[key: string]: any;
@@ -766,7 +766,7 @@ export class NgSelectOption implements OnDestroy {
766766
export abstract class NonNullableFormBuilder {
767767
abstract array<T>(controls: Array<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormArrayElement<T, never>>;
768768
abstract control<T>(formState: T | FormControlState<T>, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl<T>;
769-
abstract group<T extends {}>(controls: T, options?: AbstractControlOptions | null): ɵNonNullableFormGroup<T>;
769+
abstract group<T extends {}>(controls: T, options?: AbstractControlOptions | null): FormGroupNonNullableFormControls<T>>;
770770
abstract record<T>(controls: {
771771
[key: string]: T;
772772
}, options?: AbstractControlOptions | null): FormRecordElement<T, never>>;

packages/forms/src/form_builder.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ interface PermissiveAbstractControlOptions extends Omit<AbstractControlOptions,
5656
// Note: these two types have been extracted into type aliases to work around a .d.ts generation
5757
// issue in TypeScript 5.7. See: https://github.com/Microsoft/TypeScript/issues/60506. The types
5858
// 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>}>;
59+
/** A map of nullable form controls. */
60+
export type ɵNullableFormControls<T> = {[K in keyof T]: ɵElement<T[K], null>};
6161

62-
/** Group of non-nullable form controls. */
63-
export type ɵNonNullableFormGroup<T> = FormGroup<{[K in keyof T]: ɵElement<T[K], never>}>;
62+
/** A map of non-nullable form controls. */
63+
export type ɵNonNullableFormControls<T> = {[K in keyof T]: ɵElement<T[K], never>};
6464

6565
/**
6666
* ControlConfig<T> is a tuple containing a value of type T, plus optional validators and async
@@ -203,7 +203,10 @@ export class FormBuilder {
203203
* * `updateOn`: The event upon which the control should be updated (options: 'change' | 'blur'
204204
* | submit').
205205
*/
206-
group<T extends {}>(controls: T, options?: AbstractControlOptions | null): ɵNullableFormGroup<T>;
206+
group<T extends {}>(
207+
controls: T,
208+
options?: AbstractControlOptions | null,
209+
): FormGroup<ɵNullableFormControls<T>>;
207210

208211
/**
209212
* @description
@@ -424,7 +427,7 @@ export abstract class NonNullableFormBuilder {
424427
abstract group<T extends {}>(
425428
controls: T,
426429
options?: AbstractControlOptions | null,
427-
): ɵNonNullableFormGroup<T>;
430+
): FormGroup<ɵNonNullableFormControls<T>>;
428431

429432
/**
430433
* Similar to `FormBuilder#record`, except any implicitly constructed `FormControl`

0 commit comments

Comments
 (0)