Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
273 stars 55 forks source link

Cannot read nested union types on client side #101

Closed Dzoukr closed 5 years ago

Dzoukr commented 5 years ago

In shared project, I have DU for errors:

type TextValue =
    | Email

type DomainError =
    | ItemAlreadyExists of TextValue

type ServerError =
    | DomainError of DomainError

type ServerResponse<'a> = Async<Result<'a, ServerError>>

and proxy defined as:

type API = {
    Register : Account -> ServerResponse<Guid>
}

On error (in Result), the payload is serialized to:

{"Error":{"DomainError":{"ItemAlreadyExists":"Email"}}}

But when handling on client side, the automatic deserialization fails with:

Cannot convert ["JObject",{"comparer":{},"tree":["MapOne","Error",["JObject",{"comparer":{},"tree":["MapOne","DomainError",["JObject",{"comparer":{},"tree":["MapOne","ItemAlreadyExists",["JString","Email"]]}]]}]]}] to ["Any",null]

Is it because of nested union types or there is problem with transfering Result types as such?

Thanks a lot for help

Zaid-Ajaj commented 5 years ago

Hello there @Dzoukr, do you happen to use the latest Fable compiler? @alfonsogarciacaro said he broke something with reflection in the Result<'a> type, see this issue

It should have been fixed in v2.1.2, can you please check?

In any case, remoting can handle nested unions without problems, see protocol definition of tabula-rasa which looks very similar to yours

alfonsogarciacaro commented 5 years ago

Yes, please try with 2.1.2 or higher, sorry for the trouble. Please ping me if it's still not working.

Dzoukr commented 5 years ago

Damn guys, you are fast! No wonder you are stars of F# OSS world! Yes, that was it, thank you both and sorry for not checking that I'm running on the latest version. Paket outdated is in my blood now, but yarn outdated is something I'm still keep forgetting. 😄

Thanks again!