DEV Community

Cover image for Creating Type-Safe Forms in Angular: Advanced Tip 🤯

Creating Type-Safe Forms in Angular: Advanced Tip 🤯

Erik Cunha on August 11, 2023

When developing complex applications in Angular, one common challenge is dealing with forms and their validation. As applications grow, so does the...
Collapse
 
th3erik profile image
Erik Cunha • Edited

@rajanchavda Good catch, I think you can just follow the same idea and extend like:

export type WithControlsFrom<T> = {
  [P in keyof T]?: FormControl<T[P]> | FormArray<FormControl<T[P]>> | FormGroup<{ [K in keyof T]: FormControl<T[K]> }>;
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rajanchavda profile image
Rajan Chavda

This will not work if we want to use FormArray inside a FormGroup using common type WithControlsFrom, right ?