Created
October 4, 2023 09:22
-
-
Save ReVoid/8b426bff092f95d23f2466ed5992f8ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type Validator<T> = (value: T) => boolean; | |
class FormInput<T> { | |
constructor(public value: T, public validators: Validator<T>[]){} | |
get isValid(): boolean { | |
return this.validators.every(v => v(this.value)); | |
} | |
} | |
class FormGroup<T extends object> { | |
constructor(public inputs: { [K in keyof T]: FormInput<T[K]>}) {} | |
get isValid(): boolean { | |
return Object.values(this.inputs).every((v: any) => v.isValid === true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment