mobx-state-tree
mobx-state-tree copied to clipboard
The todo demo in document rewrite by typescript but has type error
Question
- [x] I've checked documentation and searched for existing issues
- [x] I tried the spectrum channel
Hi guys, I want to rewrite the todo demo in document by typescript, but when I try to rewrite the rooter I meet a question. That is when I use views api in RootStore, like this, but I get the type error. How can I fix this
Object is possiblity undefined you can fix in two ways
Item?.done
or item.done!
Second one is not recommended because you can get undefined at run time. In first One you can add some aditional logic to handle situations when you get undefined e ex to put a default value if done is undefined like item?.done ?? "Default value"
. But for this use case you don't have to handle if done is undefined
Hey @zhuyuedlut, I think @zhuyuedlut's answer is correct here, so I'm going to close this out.
Thanks y'all!