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

TS2345 when using Result with pipe #59

Closed
ChambreNoire opened this issue Dec 7, 2022 · 5 comments
Closed

TS2345 when using Result with pipe #59

ChambreNoire opened this issue Dec 7, 2022 · 5 comments

Comments

@ChambreNoire
Copy link

Hello,

I'm getting a TS error when using Result and pipe and have no idea why!

const processEvent = (
    event: MessageEvent<unknown>,
    handle: (event: ServerEvent) => void,
    error: (error: string) => void
) => {
    pipe(
        R.fromNullable(event, 'Incoming sse/ws message is null!'),
        R.map((event) => event.data), // <--- ERROR HERE
        R.flatMap((data: unknown) => {
            try {
                if (G.isString(data)) return R.Ok(JSON.parse(data));
            } catch (_error) {
                /* ignored */
            }
            return R.Error('Invalid incoming sse/ws message format!');
        }),
        R.flatMap((json: string) => {
            try {
                return R.Ok(ServerEventSchema.parse(json));
            } catch (_error) {
                return R.Error('Invalid incoming sse/ws message schema!');
            }
        }),
        R.tapError(error),
        R.tap(handle)
    );
};

The message I get is the following:

TS2345: Argument of type 'Result<unknown, unknown>' is not assignable to parameter of type '(arg: Result<MessageEvent<unknown>, "Incoming sse/ws message is null!">) => Result<unknown, "Invalid incoming sse/ws message format!">'.   Type 'Ok<unknown>' is not assignable to type '(arg: Result<MessageEvent<unknown>, "Incoming sse/ws message is null!">) => Result<unknown, "Invalid incoming sse/ws message format!">'.     Type 'Ok<unknown>' provides no match for the signature '(arg: Result<MessageEvent<unknown>, "Incoming sse/ws message is null!">): Result<unknown, "Invalid incoming sse/ws message format!">'.

Any ideas?

Thanks!

@mobily
Copy link
Owner

mobily commented Dec 7, 2022

@ChambreNoire what ts-belt version do you use?

@ChambreNoire
Copy link
Author

ChambreNoire commented Dec 8, 2022

@mobily I'm using v3.13.1 with Typescript v4.9.4

@mobily
Copy link
Owner

mobily commented Dec 8, 2022

v3.13.1

could you try with v4.0.0-rc.1? (you can install that version with the @next tag)

@ChambreNoire
Copy link
Author

@mobily yup that did the trick! thanks!

@mobily
Copy link
Owner

mobily commented Dec 8, 2022

@ChambreNoire awesome! 🎉 glad I could help :)

@mobily mobily closed this as completed Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants