Skip to content

Commit

Permalink
fix: narrow Either.getOrThrow implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Jul 1, 2024
1 parent 40a3647 commit 09e05e6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/domain/entities/generic/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
export class Either<Error, Data> {
constructor(public value: EitherValue<Error, Data>) {}

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<Res>(matchObj: MatchObject<Error, Data, Res>): Res {
Expand Down

0 comments on commit 09e05e6

Please sign in to comment.