As far as I know you cant really customize how DUs are represented in JavaScript. NamedUnionCasesAttribute on the type and NameAttribute only affect Json serializayion. That being said having the following type:

1
2
[<NamedUnionCases "tag">]
type Foobar = | [<Name "foo">] Foo of value : int

maybe you could use Json.Encode: 'T -> obj on the values to get the right representation for values that you wish to expose. This is not the best solution obviously but this is the only thing that comes to mind which lets you customize how zour DUs look like. After encoding it the output would be something like:

1
2
3
4
{
	tag: "foo",
    value: 42
}

as a JavaScript object.

By on 4/7/2016 4:20 PM ()

Thanks, this works and is a perfectly acceptable solution!

By on 4/9/2016 5:04 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper