![](/img/trans.png)
[英]Correct way to use immutablejs (toJS and fromJS) with redux
[英]ImmutableJS/FlowType: Is it possible to typeCheck an array returned by a List.toJS()
假設我有這個不變的清單:
type Friend = {
name: string,
phone: string
}
const aList: List<Friend> = List([...])
現在,我有了一個帶有以下簽名的函數,該函數應該使用朋友的列表:
const doStuffs = (friends: Array<Friend>): any => {...}
我想用aList轉換成這樣的數組來調用它:
doStuffs(aList.toJS())
但是我有一個流錯誤, aList.toJS()
不是Array<Friend>
是否可以類型檢查aList.toJS()
的結果,還是必須這樣定義我的函數:
const doStuffs = (friends: Array<any>): any => {...}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.