If the return type is the same for all variants, I have a macro for this error, scroll to the bottom for a minimal example: <https://github.com/mratsim/trace-of-radiance/blob/master/trace_of_radiance/support/emulate_classes_with_ADTs.nim>
If the return type is not the same you need to pass it as an argument and it cannot be dynamic.