From 09e05e690326183473679cc605c8b0e752ffe27b Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Mon, 1 Jul 2024 17:54:05 +0530 Subject: [PATCH] fix: narrow Either.getOrThrow implementation --- src/domain/entities/generic/Either.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/domain/entities/generic/Either.ts b/src/domain/entities/generic/Either.ts index ecca6888..adff2c62 100644 --- a/src/domain/entities/generic/Either.ts +++ b/src/domain/entities/generic/Either.ts @@ -17,11 +17,9 @@ export class Either { constructor(public value: EitherValue) {} - getOrThrow(): Data | undefined { - if (this.isError()) { - throw this.value.error; - } - return this.value.data; + getOrThrow(): Data { + if (this.value.data) return this.value.data; + else throw this.value.error; } match(matchObj: MatchObject): Res {