问题
I seem to be getting this error
Trying to send an unsupported type through outbound port `projectRequests`
port projectRequests : Signal (Maybe (Task String ()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The specific unsupported type is:
Task.Task String ()
The types of values that can flow through outbound ports include: Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, Json.Values, and concrete records.
However this seems to be fine
port orgRequests : Signal (Task String ())
I am confused as to what is going on here.
回答1:
There are two ways you can use a port:
- Send data to out to JavaScript, where you write your own handler to deal with it. This is limited to a subset of data that can be easily transformed to JS values.
- Send
Task
s to the runtime to be scheduled for execution.
In this case you have data (Maybe
) wrapped around your Task
, so the compiler assumes (wrongly*) that you want to the use the port for purpose #1.
If you want to execute the Task
s wrapped in Just
s on the Signal
and do nothing on a Nothing
on the Signal
, you can filter out the Nothing
and unwrap the Just
with Signal.Extra.filter or Signal.filterMap identity
:
port projectRequests : Signal (Maybe (Task String ()))
port projectRequests = Signal.filterMap identity -- and then whatever you had here before
*Can you please report this error message to the error message catalog? This message could be better since it can guess your intentions from the Task
being in the type of the data you're trying to send out.
来源:https://stackoverflow.com/questions/31778519/maybe-task-not-supported-on-outbound-ports