mobx使用数组提示越界_Mobx-State-Tree-分配给数组类型
Mobx-State-Tree-分配給數(shù)組類型,會(huì)提示Type 'string[]' is not assignable to type 'IMSTArray> & IStateTreeNode>>'.
Type 'string[]' is missing the following properties from type 'IMSTArray>': spliceWithArray, observe, intercept, clear, and 4 more.ts(2322)錯(cuò)誤import { cast } from "mobx-state-tree"
// .....
self.stores = cast(stores)
Mobx-State-Tree提供的cast方法,這個(gè)方法僅在TypeScript中累積,因?yàn)樗呀?jīng)將進(jìn)入?yún)⒌念愋娃D(zhuǎn)換成對(duì)應(yīng)的狀態(tài)的類型,因此代碼的類型能通過(guò)TypeScript的檢測(cè)(因?yàn)樵赥ypeScript看來(lái),沒有cast的時(shí)候,等號(hào)左側(cè)和右側(cè)的兩個(gè)值并非類型匹配的)。
或者:self.stores.replace(stores)
總結(jié)
以上是生活随笔為你收集整理的mobx使用数组提示越界_Mobx-State-Tree-分配给数组类型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: 核爆rpg手机版_好嗨游戏:不玩吃亏 ,
- 下一篇: 上海欢乐谷哪些项目适合小孩玩
