【发布时间】:2019-06-06 14:10:29
【问题描述】:
我想创建包含其他商店的 rootStore。问题是孩子包含如下属性:
id: types.identifier(types.string),
当我创建 rootStore 时,我从孩子那里得到一个错误:
[mobx-state-tree] 将
{}转换为SomeModelStore时出错:在路径“/id”值undefined不可分配给类型:identifier(string)(值不是字符串),应为identifier(string)的实例或类似identifier(string)的快照。
我尝试使用types.late,但没有帮助。
我找到的解决方案是将所有属性包装到types.maybe
例子:
错误: https://codesandbox.io/s/yvnznxyvyj?module=%2Fmodels%2FSomeModelStore.js
解决方法: https://codesandbox.io/s/0mv558yq50?module=%2Fmodels%2FSomeModelStore.js
【问题讨论】:
标签: javascript mobx mobx-state-tree