Skip to content
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 Errors and Context as NonEmptyArray #670

Open
devkat opened this issue Nov 2, 2022 · 0 comments · May be fixed by #671
Open

Type Errors and Context as NonEmptyArray #670

devkat opened this issue Nov 2, 2022 · 0 comments · May be fixed by #671

Comments

@devkat
Copy link

devkat commented Nov 2, 2022

🚀 Feature request

Current Behavior

Errors and Context are typed as Array:

export interface Context extends ReadonlyArray<ContextEntry> {}
export interface Errors extends Array<ValidationError> {}
export type Validation<A> = Either<Errors, A>

Desired Behavior

Errors should be typed as NonEmptyArray, since the absence of errors would constitute a success (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:

export interface Context extends ReadonlyNonEmptyArray<ContextEntry> {}

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

Software Version(s)
io-ts 2.2.19
fp-ts 2.9.5
TypeScript 4.8.2
devkat added a commit to devkat/io-ts that referenced this issue Nov 2, 2022
@devkat devkat linked a pull request Nov 2, 2022 that will close this issue
devkat added a commit to devkat/io-ts that referenced this issue Nov 2, 2022
@devkat devkat changed the title Type Errors as NonEmptyArray Type Errors and Context as NonEmptyArray Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant