# automatic conversion for fields of a parametric struct

**URL:** https://discourse.julialang.org/t/automatic-conversion-for-fields-of-a-parametric-struct/10736
**Category:** New to Julia
**Tags:** parametric-types
**Created:** [May 5, 2018, 9:10pm UTC](https://discourse.julialang.org/t/automatic-conversion-for-fields-of-a-parametric-struct/10736 "2018-05-05T21:10:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [May 6, 2018, 6:37am UTC](https://discourse.julialang.org/t/automatic-conversion-for-fields-of-a-parametric-struct/10736/2 "2018-05-06T06:37:35Z")

</div>

Ignore the last part of the error as this is not from a call to a constructor, you are calling convert() directly.

As you have just defined this custom type yourself there is no existing method for convert(Type{AwesomeStruct{Union{Void,Int64}}, AwesomeStruct{Void})

But you can easily write a general method for any AwesomeStruct T:

```julia
julia> import Base: convert

julia> convert(t::Type{AwesomeStruct{T}}, x::AwesomeStruct) where T = t(x.awesome_field)
convert (generic function with 1 method)

julia> convert(AwesomeStruct{Union{Void,Int64}}, x)
AwesomeStruct{Union{Int64, Void}}(nothing)

```

But why do you want to convert it anyway? Why do you need a union type?

---

_[View the full topic](https://discourse.julialang.org/t/automatic-conversion-for-fields-of-a-parametric-struct/10736)._
