Skip to content

Incorrect type inference when crossing async boundary #105

@jaydenfyi

Description

@jaydenfyi

Hi there,

I had a quick play around with the library and noticed the return types aren't reflecting the runtime values when switching from sync to async code.

import { Result } from '@praha/byethrow';

const doublePlusFive = Result.pipe(
  //    ^?
  // (sync) initial value
  Result.succeed(5),
  // (sync -> async) return a promise to cross into async code
  Result.map((x) => {
    return Promise.resolve(x * 2);
  }),
  // (async) map the value from the previous step
  Result.map((x) => {
    //        ^?
    return x + 5; // x is actually 10 here at runtime, but types suggest it's a promise
  })
);
// test is actually a promise returning a Result at runtime, but types suggest it's a sync Result

Playground link

To be honest I'm not confident it's possible to get the types for this to work properly without having separate sync and async implementations of every function. But hopefully it's an easy fix or I'm just doing something incorrectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions