Elm Http.post需要生成Http.Request Int,但send需要Http.Request字符串
我解码Http.post请求的响应,其中返回类型为整数: 我的问题是我使用了Http.send,它需要字符串: 我不知道如何改变退货类型。我的错误消息如下:Elm Http.post需要生成Http.Request Int,但send需要Http.Request字符串,elm,Elm,我解码Http.post请求的响应,其中返回类型为整数: 我的问题是我使用了Http.send,它需要字符串: 我不知道如何改变退货类型。我的错误消息如下: The 2nd argument to `send` is not what I expect: 113| Http.send Resolved (Http.post deadlineUrl (encodeBody value |> Http.jsonBody) responseDecoder)
The 2nd argument to `send` is not what I expect:
113| Http.send Resolved (Http.post deadlineUrl (encodeBody value |> Http.jsonBody) responseDecoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This `post` call produces:
Http.Request Int
But `send` needs the 2nd argument to be:
Http.Request String
Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!
Hint: Want to convert an Int into a String? Use the String.fromInt function!
type Msg = Resolved (Result Http.Error String)
有人能帮忙吗?我只是在和Elm玩,但我被困在这里了
我的问题是我使用了Http.send,它需要字符串
根据,send函数要求参数的类型为Request a,其中a可以是任何Int或String类型或其他类型
您遇到的问题就是编译错误中的提示所说的:
提示:我总是从左到右找出参数类型。如果有争论
是可以接受的,我假设它是“正确的”,然后继续。所以问题可能实际上是
在前面的一个论点中
因此,似乎您已经在某个地方定义了,您需要字符串,并且编译器推断了请求字符串的类型。例如,您可能已将已解析的定义如下:
The 2nd argument to `send` is not what I expect:
113| Http.send Resolved (Http.post deadlineUrl (encodeBody value |> Http.jsonBody) responseDecoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This `post` call produces:
Http.Request Int
But `send` needs the 2nd argument to be:
Http.Request String
Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!
Hint: Want to convert an Int into a String? Use the String.fromInt function!
type Msg = Resolved (Result Http.Error String)
编译器将send的多态类型推断为:Result Error a->msg->Request a->Cmd msg,因为它已经看到第一个参数是或type Result Error String->msg:
因此,在这种情况下,解决方案是更改预期类型:
type Msg = Resolved (Result Http.Error Int)
或更改解码器并将响应解码为字符串:
我的问题是我使用了Http.send,它需要字符串
根据,send函数要求参数的类型为Request a,其中a可以是任何Int或String类型或其他类型
您遇到的问题就是编译错误中的提示所说的:
提示:我总是从左到右找出参数类型。如果有争论
是可以接受的,我假设它是“正确的”,然后继续。所以问题可能实际上是
在前面的一个论点中
因此,似乎您已经在某个地方定义了,您需要字符串,并且编译器推断了请求字符串的类型。例如,您可能已将已解析的定义如下:
The 2nd argument to `send` is not what I expect:
113| Http.send Resolved (Http.post deadlineUrl (encodeBody value |> Http.jsonBody) responseDecoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This `post` call produces:
Http.Request Int
But `send` needs the 2nd argument to be:
Http.Request String
Hint: I always figure out the argument types from left to right. If an argument
is acceptable, I assume it is “correct” and move on. So the problem may actually
be in one of the previous arguments!
Hint: Want to convert an Int into a String? Use the String.fromInt function!
type Msg = Resolved (Result Http.Error String)
编译器将send的多态类型推断为:Result Error a->msg->Request a->Cmd msg,因为它已经看到第一个参数是或type Result Error String->msg:
因此,在这种情况下,解决方案是更改预期类型:
type Msg = Resolved (Result Http.Error Int)
或更改解码器并将响应解码为字符串: