swan-io / boxed

Essential building-blocks for functional & safe TypeScript code

Home Page:https://swan-io.github.io/boxed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Result.get()` can't accept outside `Result.isOk` scope even if `Result.isError()` checked and return before.

TrungRueta opened this issue · comments

const a = async () => {
       const createAcc = await Result.fromPromise(
		auth.createUser({
			displayName: name,
			email,
			emailVerified: false,
			password
		})
	);
	
  if (createAcc.isError()) return createAcc
// we should allow get value here because we catched error case and return before.
  const acc = createAcc.get()
}

Hi, i think this case is common, in functions, return error catched before get final result give cleaner code, if only check isOk() with a scope we will end up many nested if.

For now error show like this :

image

Hi! Thanks for the report. This is known issue, we're currently investigating if we can manage to get a better DX for this while preserving other key features.

I'll write down about the progress in the coming days in this thread.

Hello,

I have the same error in a case that looks similar. In my case, I am using an Option inside a Result. The goal is to represent something that can either be a Some<string> or a None or an error. See this typescript playground.

Is there any workaround to this?

Thanks!

Hi @drazik ! I already fixed all of this in #25
I'm just waiting for a peer review.

@drazik @TrungRueta This is fixed in latest version, give it a try!