question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS2345 when using Result with pipe

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ChambreNoirecommented, Dec 8, 2022

@mobily yup that did the trick! thanks!

0reactions
mobilycommented, Dec 8, 2022

@ChambreNoire awesome! 🎉 glad I could help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS2345: Argument of type 'OperatorFunction<User, void ...
Why I am getting error from pipe and map from the following code? 416 · Typescript: Type 'string | undefined' is not assignable...
Read more >
pipe(catchError()) type issues. #3673 - ReactiveX/rxjs - GitHub
@martinsik My local project is using 2.6.2 . Couldn't find TS version on the StackBlitz.
Read more >
Practical Guide to Fp-ts P1: Pipe and Flow - Ryan's Blog
Learn how to use Fp-ts practically. Introduces the pipe and flow operators. No mathematical knowledge required.
Read more >
What does the mean of pipe (|) symbol in Typescript
error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. Example 3: Using operations associated with ...
Read more >
zodern:relay - Packosphere
1import { add } from '/imports/methods/add' 2 3add([1, 2]).then(result => { 4 ... Instead of defining a single run function, a pipeline allows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found