You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To be able to serialise into a typical (untagged) typescript union I propose adding support for a JsonUnionEncoding.Untagged ||| JsonUnionEncoding.UnwrapSingleFieldCases combination that support untagged and unwrapped cases.
Types such as the one below are quite common, and adding a tag is unnecessary and unwanted in this case.
type Value = number | number[]
The equivalent type in FSharp would be as follows.
type Value = Choice<decimal, decimal list>
If we support primitive types with the constraint of one unique type per case we can also support deserializing without ambiguity.
Looking at the type type ChoiceOf5 = Choice<int, string, bool, int list, Object> we can deserialize the type knowing only the JsonTokenType. So the following type can be round trip-able without any tags.
Is there any reason this feature is not acknowledged or does it just need help to implement? I see there already is an old PR for this also that has been ignored. Is there some issue with the approach it is taking?
Although, since there is already a feature to unwrap untagged object, I think this feature should only target single non-object single values (Not sure how arrays behave with the other existing options).
E.g. a use case from the language server protocol definitions:
To be able to serialise into a typical (untagged) typescript union I propose adding support for a
JsonUnionEncoding.Untagged ||| JsonUnionEncoding.UnwrapSingleFieldCases
combination that support untagged and unwrapped cases.Types such as the one below are quite common, and adding a tag is unnecessary and unwanted in this case.
The equivalent type in FSharp would be as follows.
If we support primitive types with the constraint of one unique type per case we can also support deserializing without ambiguity.
Looking at the type
type ChoiceOf5 = Choice<int, string, bool, int list, Object>
we can deserialize the type knowing only the JsonTokenType. So the following type can be round trip-able without any tags.Duplicate types could fail or attempt to pick the first matching type.
The text was updated successfully, but these errors were encountered: