mobx-state-tree icon indicating copy to clipboard operation
mobx-state-tree copied to clipboard

The todo demo in document rewrite by typescript but has type error

Open zhuyuedlut opened this issue 4 years ago • 1 comments

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

2020-11-05_105720

zhuyuedlut avatar Nov 05 '20 02:11 zhuyuedlut

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

Relaxe111 avatar Jan 13 '21 21:01 Relaxe111

Hey @zhuyuedlut, I think @zhuyuedlut's answer is correct here, so I'm going to close this out.

Thanks y'all!

coolsoftwaretyler avatar Jun 28 '23 17:06 coolsoftwaretyler