-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-safe safeValue
#58
Comments
Related discussion: https://github.com/qbox/horn/pull/340#discussion_r699824181 |
Some ideas: 1. Auto type inference by validatorsconst state = new FieldState<string | null>('').validators(notNull) // safeValue: string It's hard, maybe impossible 2. Generic type passing with validatorconst state = new FieldState<string | null>('').validators<string>(notNull) // safeValue: string 3. Generic type passing with constructorconst state = new FieldState<string | null, string>('').validators(notNull) // safeValue: string 4. Type assertion while read
|
One thing to consider: should this value be defined and available even when validators return errors? But if this value is always defined, regardless of latest validation result, then I would suggest not linking the safeType with validators as in 2. |
Accessing safe-value will throw if currently validation not passed. @computed get safeValue() {
if (!this.validated || this.hasError) throw new Error('TODO')
return this.value
} |
safeValue
is like$
ofFieldState
in formstate-x v2, while with some differences:safeValue
(or something else) instead of$
FormState
,ArrayFormState
, etc.) will providesafeValue
The text was updated successfully, but these errors were encountered: