Elm中的Maybe和嵌套资源错误



我正在构建我的第一个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

我做错了什么?提前非常感谢!

Update.update函数类型不匹配。

update : Msg -> Model -> ( Model, Cmd Msg )

您必须处理Update.elm中的Maybe值:

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 ->
            case model.contact of
                Just contact ->
                    let
                        ( updatedContact, cmd ) =
                            Contact.Update.update subMsg contact
                    in
                        ( { model | contact = updatedContact }
                        , Cmd.map ContactMsg cmd
                        )
                Nothing ->
                    ( model, Cmd.none )

最新更新