Skip to content

Commit

Permalink
feat: restore old ok and err behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
braden-w committed Dec 25, 2024
1 parent fe51ba1 commit d1d5257
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-berries-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@epicenterhq/result": patch
---

Restore old ok and err behavior
18 changes: 7 additions & 11 deletions src/result.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
export type Result<T, E> = { ok: true; data: T } | { ok: false; error: E };
export type Ok<T> = { ok: true; data: T };
export type Err<E> = { ok: false; error: E };

export type Ok<T> = Result<T, never>;
export type Err<E> = Result<never, E>;
export type Result<T, E> = Ok<T> | Err<E>;

export type InferOk<R extends Result<unknown, unknown>> = R extends Result<
infer U,
never
>
? Ok<U>
export type InferOk<R extends Result<unknown, unknown>> = R extends Ok<infer U>
? U
: never;

export type InferErr<R extends Result<unknown, unknown>> = R extends Result<
never,
export type InferErr<R extends Result<unknown, unknown>> = R extends Err<
infer E
>
? Err<E>
? E
: never;

export const Ok = <T>(data: T): Ok<T> => ({ ok: true, data });
Expand Down

0 comments on commit d1d5257

Please sign in to comment.