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

feat: add ResultValue and ResultError helper types #591

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export { Result, ok, Ok, err, Err, fromThrowable, safeTry } from './result'
export { Err, Ok, Result, err, fromThrowable, ok, safeTry } from './result'
export {
ResultAsync,
okAsync,
errAsync,
fromAsyncThrowable,
fromPromise,
fromSafePromise,
okAsync,
} from './result-async'
export type { ResultError } from './result-error'
export type { ResultValue } from './result-value'
12 changes: 12 additions & 0 deletions src/result-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Result } from 'result'
import { ResultAsync } from 'result-async'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
lucaschultz marked this conversation as resolved.
Show resolved Hide resolved
export type ResultError<T extends Result<any, any> | ResultAsync<any, any>> = T extends Result<
infer _,
infer E
>
? E
: T extends ResultAsync<infer _, infer E>
? E
: never
12 changes: 12 additions & 0 deletions src/result-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Result } from 'result'
import { ResultAsync } from 'result-async'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ResultValue<T extends Result<any, any> | ResultAsync<any, any>> = T extends Result<
infer U,
infer _
>
? U
: T extends ResultAsync<infer U, infer _>
? U
: never