typescript-result
typescript-result copied to clipboard
Question: Strange behavior on generic functions return `Result`
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]
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.
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.
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.
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>'.
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!