Properly exporting foreign types in module - for save/load JLD2

Hey!
I’ve got a questing on modules and (re-)exporting types imported from another module.
The MWE below shows my problem.
I want to use/export a type from a different module. This works fine.
However I cannot load such an object from file.

Two workarounds are to either do import Distances manually or to use @reexport in my module.
The first option is not really satisfactory and the second one clutters my namespace
since I only need one single name out of a large package.
(Distances was only an example )

julia> module Foo
           import Distances:Euclidean
           export Euclidean
       end
Main.Foo

julia> bar = Foo.Euclidean()
Distances.Euclidean(0.0)

julia> using FileIO

julia> save("testfile.jld2", "bar", bar)

julia> bar2 = load("testfile.jld2", "bar")
┌ Warning: type Distances.Euclidean does not exist in workspace; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/KjBIK/src/data.jl:1153
getfield(JLD2.ReconstructedTypes, Symbol("##Distances.Euclidean#358"))(0.0)

julia> bar == bar2
false

ulia> import Distances

julia> bar3 = load("testfile.jld2", "bar")
Distances.Euclidean(0.0)

julia> bar == bar3
true
1 Like