Skip to content

Commit

Permalink
refactor: simplify Result type definition by consolidating Ok and Err…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
braden-w committed Dec 24, 2024
1 parent e4db821 commit 57a88a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-owls-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@epicenterhq/result": patch
---

Simplify Result type definition by consolidating Ok and Err types
13 changes: 3 additions & 10 deletions src/result.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
export type Ok<T> = {
ok: true;
data: T;
};
export type Result<T, E> = { ok: true; data: T } | { ok: false; error: E };

export type Err<E> = {
ok: false;
error: E;
};

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

export type InferOk<R extends Result<unknown, unknown>> = R extends Ok<infer U>
? U
Expand Down

0 comments on commit 57a88a6

Please sign in to comment.