Last active
July 21, 2023 07:14
-
-
Save NetanelBasal/26395c1e1dca3712ab9ecb6c99ac23d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Profile { | |
firstName: string; | |
lastName: string; | |
address: { | |
street: string; | |
city: string | |
} | |
} | |
const profileForm = new FormGroup<ControlsOf<Profile>>({ | |
firstName: new FormControl('', { nonNullable: true }), | |
lastName: new FormControl('', { nonNullable: true }), | |
address: new FormGroup({ | |
street: new FormControl('', { nonNullable: true }), | |
city: new FormControl('', { nonNullable: true }) | |
}) | |
}); | |
export type ControlsOf<T extends Record<string, any>> = { | |
[K in keyof T]: T[K] extends Record<any, any> | |
? FormGroup<ControlsOf<T[K]>> | |
: FormControl<T[K]>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Has anyone found a solution? How to use ControlsOf(...) with optional controls?