From d1d5257e8767c543c3b02cc47b312b103a67c5b4 Mon Sep 17 00:00:00 2001 From: Braden Wong <13159333+braden-w@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:12:34 -0800 Subject: [PATCH] feat: restore old ok and err behavior --- .changeset/cyan-berries-rhyme.md | 5 +++++ src/result.ts | 18 +++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 .changeset/cyan-berries-rhyme.md diff --git a/.changeset/cyan-berries-rhyme.md b/.changeset/cyan-berries-rhyme.md new file mode 100644 index 0000000..9a4baac --- /dev/null +++ b/.changeset/cyan-berries-rhyme.md @@ -0,0 +1,5 @@ +--- +"@epicenterhq/result": patch +--- + +Restore old ok and err behavior diff --git a/src/result.ts b/src/result.ts index 6b90833..738d85a 100644 --- a/src/result.ts +++ b/src/result.ts @@ -1,20 +1,16 @@ -export type Result = { ok: true; data: T } | { ok: false; error: E }; +export type Ok = { ok: true; data: T }; +export type Err = { ok: false; error: E }; -export type Ok = Result; -export type Err = Result; +export type Result = Ok | Err; -export type InferOk> = R extends Result< - infer U, - never -> - ? Ok +export type InferOk> = R extends Ok + ? U : never; -export type InferErr> = R extends Result< - never, +export type InferErr> = R extends Err< infer E > - ? Err + ? E : never; export const Ok = (data: T): Ok => ({ ok: true, data });