mobx使用数组提示越界_Mobx-State-Tree-分配给数组类型
生活随笔
收集整理的這篇文章主要介紹了
mobx使用数组提示越界_Mobx-State-Tree-分配给数组类型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Mobx-State-Tree-分配給數組類型,會提示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)錯誤import { cast } from "mobx-state-tree"
// .....
self.stores = cast(stores)
Mobx-State-Tree提供的cast方法,這個方法僅在TypeScript中累積,因為他已經將進入參的類型轉換成對應的狀態的類型,因此代碼的類型能通過TypeScript的檢測(因為在TypeScript看來,沒有cast的時候,等號左側和右側的兩個值并非類型匹配的)。
或者:self.stores.replace(stores)
總結
以上是生活随笔為你收集整理的mobx使用数组提示越界_Mobx-State-Tree-分配给数组类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 核爆rpg手机版_好嗨游戏:不玩吃亏 ,
- 下一篇: 上海欢乐谷哪些项目适合小孩玩