Skip to content

Avoiding type assertions for sub-models #760

Answered by meowgorithm
yrashk asked this question in Q&A
Discussion options

You must be logged in to vote

That's very nice. We've discussed changing Model and Program.Run to use generics internally, however because it's a breaking change we don't expect to apply it until the next major version.

For what it's worth, it's perfectly fine to not implement tea.Model on children:

// On the child. We return the concrete type rather than an abstract tea.Model.
func (m ChildModel) Update(msg tea.Msg) (ChildModel, tea.Cmd) { /* ... */ }

// In the parent. No assertion necessary.
m.child, cmd = m.child.Update(msg)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yrashk
Comment options

Answer selected by bashbunni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants