DEV Community

Discussion on: Modelling remote data in ReasonReact

Collapse
 
idkjs profile image
Alain • Edited

Greeting Ms. Krutikova,

Thanks again for taking the time to share this. Would you mind explaining to me the difference between these two functions? The seem to do the same thing.

let toLoading = (data: t('data)) =>
  RemoteData.(Loading(data |> map(d => Some(d)) |> withDefault(None)));
let toLoading = (data: t('data)): t('data) =>
  RemoteData.(Loading(data |> map(d => Some(d)) |> withDefault(None)));

Posting screenshot for the annotations. Looks like the second one makes sure that the type returned is t('data) for some reason. Is that right?

Can't get devto to load the screenshot so here is the link they provided.
thepracticaldev.s3.amazonaws.com/i...

Tack!

Collapse
 
margaretkrutikova profile image
Margarita Krutikova

Thank you for your feedback!

Those two functions do exactly the same, the return type annotation in the second case is redundant since the type is inferred by the compiler, but might make it more clear for those who are going to read the code (however, unlikely 😉). I would say the type annotation is unnecessary.