【发布时间】:2016-06-23 18:46:30
【问题描述】:
我在试用 Elm 时遇到了一个问题。我想通过端口传递联合类型,但出现此错误:
Port `setStorage` is trying to communicate an unsupported type.
34| port setStorage : Model -> 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.
我已将 Todo example 修改如下:
type alias Task =
{ description : String
, completed : Bool
, editing : Bool
, id : Int
, importance : Importance -- <- this is the new field
}
type Importance
= Normal
| High
| Low
这个issue 似乎很老了。一位评论者建议“通过端口传递 Json.Values 并对其进行 Json.Decode/Encode”,但具体该怎么做呢?该文档似乎有点不清楚,并且缺少完整的示例。任何帮助表示赞赏。
【问题讨论】: