Date objects losing their type during `invoke`

I’m building some objects in a (typescript) resolver, which is then invoked from my UI-Kit component (a DatePicker onChange function).

The objects have a property of type Date when I construct them, and I can call Date methods on those properties while in the resolver.

When I have the objects in the UI kit component, they have mostly the right type, except for the date properties. I have to wrap those properties in new Date() to get them back to the right type.

The constructor of the object is doing the right thing, so the objects aren’t being created via the constructor, they’re presumably being marshaled and unmarshaled via introspection, JSON.stringify+JSON.parse or something like that.

Is the marshaling / unmarshaling configurable? Can I tell forge-bridge how to reconstruct my objects so that all properties have the right type?

You could use a library like superjson, which serializes Date and other types to a JSON format that can be deserialized with the correct types on the client.

That’s pretty much what I’m asking: how do I influence the serialization? Do I just have to return a pre-serialized object as a string, so that whatever magic Forge is performing between the resolver and the UI kit component is happening to a string? Or can I insert superjson (or my own logic) in there somewhere, maybe via a serialization callback, so that Forge does the right thing on my behalf?

I think you have to serialize and deserialize the returned objects yourself.