-
Notifications
You must be signed in to change notification settings - Fork 6
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
map breaks RemoteData types #53
Comments
mksmtn
changed the title
map should map inProgress and failure values
map breaks RemoteData types
May 20, 2023
Hi @mksmtn , I don't use the
export type RemoteData<T, E = string> =
| NotAsked
| InProgress
| Failure<E>
| Success<T>;
All those pipes wouldn't be needed anymore. |
@joanllenas will you implement those changes yourself? If you don't have time, probably I will be able to make a PR in June |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for the package, I use it a lot at in my projects. I have a bug report.
map
function from the package working only onSuccess
values makes typing incorrect. And I've spent hours to find the root reason for my code giving me a value of a type in runtime that I don't expect.Typically,
Failure
andInProgress
have the last successfully fetched value, so they're of same type, and it's even built into theRemoteData
type. In the current implementation, however, we can usemap
and change type of aSuccess
value, butInProgress
andFailure
values stay the same, and it creates a mismatch between compile time types and run time types.We can't simply change the current implementation to
!isNotAsked(rd) && rd.value !== undefined ? fn(rd.value) : rd
, because thefn
won't be called withundefined
even if it's an expectedSuccess
value. We can't makefn
argument type(a: A | undefined) => B
either, as we will force our clients to always mapundefined
to aB
value, thus creating a value forinProgress
even wheninProgress
was called without arguments. I guess the only sound solution, however sad it would be, is to abandoninProgress
andFailure
values altogether and force our clients to store the latest successful value themself.The text was updated successfully, but these errors were encountered: