title: How to pass union types through Elm ports?
body: <p>I've bumped into an issue while trying out Elm. I want to pass a union type through a port but I get this error:</p>
  
  <pre><code>Port `setStorage` is trying to communicate an unsupported type.
  
  34| port setStorage : Model -&gt; Cmd msg
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  The specific unsupported type is:
  
      Todo.Importance
  
  The types of values that can flow through in and out of Elm include:
  
      Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,
      Tuples, Json.Values, and concrete records.
  </code></pre>
  
  <p>I've modified the Todo <a href="https://github.com/evancz/elm-todomvc/blob/master/Todo.elm" rel="nofollow noreferrer">example</a> as follows:</p>
  
  <pre><code>type alias Task =
      { description : String
      , completed : Bool
      , editing : Bool
      , id : Int
      , importance : Importance -- &lt;- this is the new field
      }
  
  type Importance
    = Normal
    | High
    | Low
  </code></pre>
  
  <p>This <a href="https://github.com/elm-lang/elm-compiler/issues/490" rel="nofollow noreferrer">issue</a> appears to be quite old. One commenter suggests to "pass Json.Values through ports and Json.Decode/Encode them" but how exactly to do that? The documentation appears a bit unclear and lacks full examples. Any help appreciated.</p>