lune-climate / ts-results-es

A TypeScript implementation of Rust's Result and Option.
MIT License
98 stars 8 forks source link

Result.orElse is broken ("This expression is not callable") #175

Open jstasiak opened 1 month ago

jstasiak commented 1 month ago

With the latest released version (4.2.0) and the development version from the master branch this code

const result = Err('boo') as Result<number, string>
const resultAfterOrElse = result.orElse((error) => Err(error))

will fail to compile:

root@54b019d15fcf:/lune/ts-results-es# npm test

> ts-results-es@4.2.0 test
> jest

 FAIL  test/result.test.ts
  ● Test suite failed to run

    test/result.test.ts:327:38 - error TS2349: This expression is not callable.
      Each member of the union type '(<R extends Result<number, unknown>>(_other: (error: never) => R) => OkImpl<number>) | (<R extends Result<unknown, unknown>>(other: (error: string) => R) => R)' has signatures, but none of those signatures are compatible with each other.

    327     const resultAfterOrElse = result.orElse((error) => Err(error))
                                             ~~~~~~
    test/result.test.ts:327:46 - error TS7006: Parameter 'error' implicitly has an 'any' type.

    327     const resultAfterOrElse = result.orElse((error) => Err(error))
                                                     ~~~~~

so it seems that Result.orElse has been broken for a while.

jstasiak commented 1 month ago

Note to self: once that compiles make sure the type of resultAfterOrElse is all right, something like

eq<typeof resultAfterOrElse, Result<number, string>>(true)

probably

jstasiak commented 1 month ago

TypeScript 5.6.2 and ts-results-es 4.2.0 BTW.

mkermani144 commented 1 month ago

Same for Result.or.