From f363d65cfcf0821ac9a0a63249a692f0e92dfcef Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 18 Dec 2024 10:20:04 +0100 Subject: [PATCH] Improve match return types inference --- src/AsyncData.ts | 10 +++++----- src/OptionResult.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/AsyncData.ts b/src/AsyncData.ts index 690bf63..1c9b063 100644 --- a/src/AsyncData.ts +++ b/src/AsyncData.ts @@ -269,14 +269,14 @@ class __AsyncData { return mapper((this as Done).value); } - match( + match( this: AsyncData, config: { - Done: (value: A) => B; - Loading: () => B; - NotAsked: () => B; + Done: (value: A) => B1; + Loading: () => B2; + NotAsked: () => B3; }, - ): B { + ): B1 | B2 | B3 { if (this === NOT_ASKED) { return config.NotAsked(); } diff --git a/src/OptionResult.ts b/src/OptionResult.ts index 323d7e9..40101ae 100644 --- a/src/OptionResult.ts +++ b/src/OptionResult.ts @@ -237,10 +237,10 @@ class __Option { /** * Explodes the Option given its case */ - match( + match( this: Option, - config: { Some: (value: A) => B; None: () => B }, - ): B { + config: { Some: (value: A) => B1; None: () => B2 }, + ): B1 | B2 { if (this === NONE) { return config.None(); } @@ -604,10 +604,10 @@ class __Result { /** * Explodes the Result given its case */ - match( + match( this: Result, - config: { Ok: (value: A) => B; Error: (error: E) => B }, - ): B { + config: { Ok: (value: A) => B1; Error: (error: E) => B2 }, + ): B1 | B2 { return this.tag === "Ok" ? config.Ok(this.value) : config.Error(this.error); }