typescript-result icon indicating copy to clipboard operation
typescript-result copied to clipboard

Question: Strange behavior on generic functions return `Result`

Open ForkKILLET opened this issue 3 months ago • 5 comments

const raise = <E>(err: E): Result<never, E> => Result.error(err)

Error:

Type 'Error<E>' is not assignable to type 'Error$1<E>'.

Version: [email protected]

ForkKILLET avatar Aug 15 '25 19:08 ForkKILLET

Same here but with Result.Ok(res) in a generic function: Type 'Ok<T>' is not assignable to type 'Result<T, Error>'. This keeps us from upgrading to even 3.3.0 from 3.1.1, where everything is fine.

gyg-persien avatar Sep 09 '25 14:09 gyg-persien

Thanks @ForkKILLET and @gyg-persien for raising this issue!

I have a repro here

Result.Error<E> should equal Result<never, E>, so I need to do some digging to see what's going on here.

everweij avatar Sep 09 '25 17:09 everweij

I've worked on a fix: https://github.com/everweij/typescript-result/releases/tag/v3.5.3-beta.1

When you have time, please check whether this beta release fixes the issues you are having and let me know.

everweij avatar Sep 09 '25 20:09 everweij

I tried out v3.5.3-beta.1 , but I still get those errors where Result.ok(<T>) is not assignable to Result<T, unknown>.

I am on Typescript ^5.9.2.

And thank you for this awesome library! :)

      Type '{ data: Result.Ok<T>; isFetching: boolean; isLoading: false; }' is not assignable to type '{ data: Result<T, unknown>; isFetching: boolean; isLoading: false; }'.
        Types of property 'data' are incompatible.
          Type 'Ok<T>' is not assignable to type 'Result<T, unknown>'.
            Type 'Result$1<T, never>' is not assignable to type 'Ok<T>'.

vdawg-git avatar Sep 12 '25 21:09 vdawg-git

Hey @vdawg-git, thanks for checking the beta release. Could you please share some code (that triggers the error message you've shared earlier) so I can identify the error and debug it locally? Feel free to use the playground (still runs v3.5.2). Thanks!

everweij avatar Sep 15 '25 12:09 everweij