Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created September 2, 2023 07:42
Show Gist options
  • Save guiseek/ef695a77d237dd6f39851d8798a3630b to your computer and use it in GitHub Desktop.
Save guiseek/ef695a77d237dd6f39851d8798a3630b to your computer and use it in GitHub Desktop.
Angular Typed Form
type DetectTypedForm<T> =
T extends Array<infer U>
? FormArray<DetectTypedForm<U>>
: T extends Date
? FormControl<Date>
: T extends object
? FormGroup<TypedForm<T>>
: T extends true | false
? FormControl<boolean>
: T extends PropertyKey
? FormControl<T>
: FormControl<unknown>
export type TypedForm<T> = {
[K in keyof T]: DetectTypedForm<T[K]>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment