From 17e6a6f2238f982af57163a1b35c8bb774352d0b Mon Sep 17 00:00:00 2001 From: Mackenzie Salisbury Date: Fri, 20 Sep 2024 00:07:52 +0200 Subject: [PATCH 1/2] Allow ok/err/okAsync/errAsync to accept zero arguments when returning void --- src/result-async.ts | 14 ++++++++++---- src/result.ts | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/result-async.ts b/src/result-async.ts index 01f2f13e..a89eec2e 100644 --- a/src/result-async.ts +++ b/src/result-async.ts @@ -207,11 +207,17 @@ export class ResultAsync implements PromiseLike> { } } -export const okAsync = (value: T): ResultAsync => - new ResultAsync(Promise.resolve(new Ok(value))) +export function okAsync(value: T): ResultAsync +export function okAsync(value: void): ResultAsync +export function okAsync(value: T): ResultAsync { + return new ResultAsync(Promise.resolve(new Ok(value))) +} -export const errAsync = (err: E): ResultAsync => - new ResultAsync(Promise.resolve(new Err(err))) +export function errAsync(err: E): ResultAsync +export function errAsync(err: void): ResultAsync +export function errAsync(err: E): ResultAsync { + return new ResultAsync(Promise.resolve(new Err(err))) +} export const fromPromise = ResultAsync.fromPromise export const fromSafePromise = ResultAsync.fromSafePromise diff --git a/src/result.ts b/src/result.ts index f2b84989..f9b8c6be 100644 --- a/src/result.ts +++ b/src/result.ts @@ -61,10 +61,15 @@ export namespace Result { export type Result = Ok | Err -export const ok = (value: T): Ok => new Ok(value) +export function ok(value: T): Ok +export function ok(value: void): Ok +export function ok(value: T): Ok { + return new Ok(value) +} export function err(err: E): Err export function err(err: E): Err +export function err(err: void): Err export function err(err: E): Err { return new Err(err) } From acea44adb98dda2ca32fe4e882879461cc7cedc2 Mon Sep 17 00:00:00 2001 From: m-shaka Date: Sun, 3 Nov 2024 23:49:41 +0900 Subject: [PATCH 2/2] Create thirty-avocados-explain.md --- .changeset/thirty-avocados-explain.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thirty-avocados-explain.md diff --git a/.changeset/thirty-avocados-explain.md b/.changeset/thirty-avocados-explain.md new file mode 100644 index 00000000..9d1b36ae --- /dev/null +++ b/.changeset/thirty-avocados-explain.md @@ -0,0 +1,5 @@ +--- +"neverthrow": minor +--- + +Allow ok/err/okAsync/errAsync to accept zero arguments when returning void