Give the following, how can I make my optional properties be optional inside the FormBuilder?
export type TypedFormControls<T extends Record<any, any>> = {
[K in keyof T]-?: T[K] extends Array<infer R>
? FormArray<
R extends Record<any, any>
? FormGroup<TypedFormControls<R>>
: FormControl<R>
>
: T[K] extends Record<any, any>
? FormGroup<TypedFormControls<T[K]>>
: FormControl<T[K]>;
};
Here are my models
export class UserModel {
email: string;
age?: number;
information?: Information;
}
export class Information {
id: number;
name: string;
gender?: string;
}
And finally the form group
this.formGroup = this._formBuilder.group<TypedFormControls<UserModel>>({
email: this._formBuilder.control('email@email'),
// age: this._formBuilder.control(25),
information: this._formBuilder.group<TypedFormControls<Information>>({
// gender: this._formBuilder.control('male'),
id: this._formBuilder.control(1),
name: this._formBuilder.control('John'),
}),
});
Here is the stackblitz