Hi,
I’ve just started getting the above JS error in a current project. I’ve kind of fixed it, but the fix/cause is strange, and wondered if anyone could shed any light on this.
I have a Wizard module, which imports a Breadcrumbs module, and the Wizard module has the following content:
type Msg
= NoOp
| BreadcrumbsMsg Breadcrumbs.Msg
update : Msg -> Model -> (Model, Maybe OutMsg)
update msg model =
case msg of
NoOp ->
(model, Nothing)
BreadcrumbsMsg subMsg ->
...
After a lot of Debug/console.logging I eventually narrowed it down to the Msg being passed into Wizard.update. I then noticed that the Msg being passed in should not arrive here, it’s the wrong type:
I know, this should be impossible right? But:
When I traced the value of msg in updates case statement, the value was StartWizardMsg OnLoseFocus, which is a msg from the button that is clicked to start the wizard, and is in a completely different module. The StartWizardMsg should never reach the Wizard.update function, if I tried to pass it in, the compiler would complain, so all I can guess is that something is happening during runtime that shouldn’t be happening.
I remembered something from long ago, where changing the order of the branches in an update function fixed a similar problem, so I switched the order of the msgs in update to be:
update msg model =
BreadcrumbsMsg subMsg ->
...
NoOp ->
(model, Nothing)
The TypeError went away, although the wrong msg is still being sent to the update function.
I then realised that the NoOp msg was left over from a refactor, and wasn’t needed, so I removed it - the TypeError came back - add the unused NoOp msg back and the TypeError goes away.
All very strange… hope I’ve explained all that okay.
Thoughts anyone?
