Public interface for ToValue customization ?
Author: vanackereCreated Aug 20, 2022Updated Sep 30, 2024
Hi,
It would be really nice if the (r *Runtime) ToValue method could support an interface to allow custom conversion to goja values, working with reflect-based objects.
My use case would be to be able to declare custom generics types in go (like Option[T], Result[T,E]) and have them automatically handled anywhere in go values (either as field of structs or values in mappings for example).
There is already an internal interface with the right signature:
type valueContainer interface {
toValue(*Runtime) Value
}However there are two problems with this interface:
- It is currently private
- AFAICT for my solution to work, this interface should also be checked in (r *Runtime) reflectValueToValue
What do you think about this ?
Source: dop251/goja