Open devkat opened 1 year ago
Errors and Context are typed as Array:
Errors
Context
Array
export interface Context extends ReadonlyArray<ContextEntry> {} export interface Errors extends Array<ValidationError> {} export type Validation<A> = Either<Errors, A>
Errors should be typed as NonEmptyArray, since the absence of errors would constitute a success (either.Right):
NonEmptyArray
either.Right
export interface Errors extends NonEmptyArray<ValidationError> {} export type Validation<A> = Either<Errors, A>
See also https://zio.github.io/zio-prelude/docs/functionaldatatypes/validation
Context should be typed as ReadonlyNonEmptyArray since at least one context should exist for an error:
ReadonlyNonEmptyArray
export interface Context extends ReadonlyNonEmptyArray<ContextEntry> {}
See pull request
The solution simplifies error handling since the user can rely on the fact that at least one error with at least one context is present.
β
π Feature request
Current Behavior
Errors
andContext
are typed asArray
:Desired Behavior
Errors
should be typed asNonEmptyArray
, since the absence of errors would constitute a success (either.Right
):See also https://zio.github.io/zio-prelude/docs/functionaldatatypes/validation
Context
should be typed asReadonlyNonEmptyArray
since at least one context should exist for an error:Suggested Solution
See pull request
Who does this impact? Who is this for?
The solution simplifies error handling since the user can rely on the fact that at least one error with at least one context is present.
Describe alternatives you've considered
β
Additional context
β
Your environment