-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.orElse() does not work properly #197
Comments
Hey @xkatianx, thank you for the report. May I ask what's the situation where you see types like this ( |
Not really class T1 { name = "T1" as const }
class T2 { name = "T2" as const }
class T3 { name = "T3" as const }
class T4 { name = "T4" as const }
class T5 { name = "T5" as const }
class T6 { name = "T6" as const }
function foo1(): Result<T1, T2> {
return 0 as any
}
function foo2(): Result<T3, T4> {
return 0 as any
}
function foo3(): Result<T5, T6> {
return 0 as any
}
const a = foo1().andThen(foo2).orElse(foo3) // error |
Some things just won't work when the type is export function asResult<T extends Result<OkContent<T>, ErrContent<T>>>(
res: T,
): Result<OkContent<T>, ErrContent<T>> {
return res;
} It'd be nice to have this built in. |
I'm on the fence if this is an |
Now I have a situation. function foo(arr?: number[]): Result<number[], null> {
return arr == null ? Err(null) : Ok(arr);
}
function unique(arr?: number[]) {
return foo(arr).andThen((a) => { // error
if (a.length === 0) return Err(new NoElementError());
if (a.length === 1) return Ok(a.pop()!);
return Err(new ManyElementsError());
});
} |
Workaround:
.andThen()
probably has the same issue.The text was updated successfully, but these errors were encountered: