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

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

Open
jstasiak opened this issue Sep 20, 2024 · 4 comments
Open

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

jstasiak opened this issue Sep 20, 2024 · 4 comments
Milestone

Comments

@jstasiak
Copy link
Collaborator

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

> [email protected] 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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

TypeScript 5.6.2 and ts-results-es 4.2.0 BTW.

@mkermani144
Copy link

Same for Result.or.

@game4353
Copy link

https://codesandbox.io/p/sandbox/clever-dew-nkmy8x
This should fix it.

@jstasiak jstasiak added this to the 5.0.0 milestone Jan 15, 2025
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

3 participants