I just fiddled around with ports and I wanted to send 2 values ( as tuple ). the Elm code copiles just fine but when I’m running the app I get this error:
Uncaught Error: Trying to send an unexpected type of value through port `storageData`:
[object Object]
this is my port / subscription / message-type in elm:
port storageData : (( String, Maybe String ) -> msg) -> Sub msg
subscriptions : Model -> Sub Msg
subscriptions _ =
storageData StorageData
type Msg
= StorageData ( String, Maybe String )
I also tried to put the 2 parameters in js in another pair of brackets so that they arent 2 parameters but 1 tuple ( I guess ) but didnt change anything
It is worth noting as well that you can always just take a Json.Value and decode it any way you like, or encode one and pass it in (as appropriate for the port direction). This is useful when you want to get differently shaped data as a custom type, for example.
Here’s the section of the guide that lists what various JS values get turned into Elm values. It’s under the section on flags but it holds true for ports too.