Skip to content
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

Wrong type definitions for R.flatMap and AR.flatMap #62

Closed
MartinRamm opened this issue Jan 4, 2023 · 1 comment
Closed

Wrong type definitions for R.flatMap and AR.flatMap #62

MartinRamm opened this issue Jan 4, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@MartinRamm
Copy link

As per documentation, the function given to flatMap is only invoked if the status is Ok. Hence, if the Result was already in an error state BEFORE R.flatMap is invoked, the state doesn't change.

While this is true at runtime, this is not how the type specification is implemented.

For example:

import {R, pipe} from '@mobily/ts-belt';

class Error1 extends Error{}
class Error2 extends Error{}

const value = Math.random() < 0.5 ? null : 'test';
const test = pipe(
  R.fromNullable(value, new Error1()),
  R.flatMap((value) => {
    return Math.random() < 0.5
        ? R.Ok(value)
        : R.Error(new Error2())
    }
  )
)
console.log(test);

The type of test should be Result<string, Error1 | Error2>, but it is Result<string, Error2>.

@mobily mobily added the bug Something isn't working label Jan 4, 2023
@mobily
Copy link
Owner

mobily commented Jan 4, 2023

@MartinRamm thanks for reporting this issue! fixed in v4.0.0-rc.4 🚀 3e6f0ec

https://github.com/mobily/ts-belt/releases/tag/v4.0.0-rc.4

@mobily mobily closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants