【发布时间】:2016-08-27 10:08:24
【问题描述】:
我正在构建我的第一个 Elm SPA,并将我的组件组织在不同的文件夹和模块中。一切正常,直到我改变了主模型:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Contact.Model.Model
, route : Routing.Route
}
到这里:
type alias Model =
{ contacts : Contacts.Model.Model
, contact : Maybe Contact.Model.Model
, route : Routing.Route
}
我已经在代码库中进行了所有必要的更改以使其正常工作,但我缺少一些我找不到的东西,因为在主 Update 模块中我经常收到此编译错误:
The type annotation for `update` does not match its definition. - The type annotation is saying:
Msg
-> { ..., contact : Maybe Contact.Model.Model }
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
But I am inferring that the definition has this type:
Msg
-> { ...
, contact :
{ birth_date : String
, email : String
, first_name : String
, gender : Int
, headline : String
, id : Int
, last_name : String
, location : String
, phone_number : String
, picture : String
}
}
-> ( { contact : Maybe Contact.Model.Model
, contacts : Contacts.Model.Model
, route : Routing.Route
}
, Cmd Msg
)
看起来我错过了在某处传递Maybe Model,但我找不到它。这是更新函数的样子:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ContactsMsg subMsg ->
let
( updatedContacts, cmd ) =
Contacts.Update.update subMsg model.contacts
in
( { model | contacts = updatedContacts, contact = Nothing }, Cmd.map ContactsMsg cmd )
ContactMsg subMsg ->
let
( updatedContact, cmd ) =
Contact.Update.update subMsg model.contact
in
( { model | contact = updatedContact }, Cmd.map ContactMsg cmd )
这是完整的 repo,错误:https://github.com/bigardone/phoenix-and-elm/tree/feature/routes-refactoring/web/elm
我做错了什么?非常感谢您!
【问题讨论】:
标签: elm