我有这个基本模型。
const stuff = types.model({
term: types.string,
excludeTerm: types.string,
stores: types.array(types.string)
}).actions(self => ({
setTerm(term: string) {
self.term = term
},
setExcludeTerm(term: string) {
self.excludeTerm = term
},
setStores(stores: string[]) {
self.stores = stores // <<< the lint error is on this line
}
}))
我收到以下 TS Lint 错误:
类型 'string[]' 不可分配给类型 'IMSTArray<ISimpleType> & IStateTreeNode<IArrayType<ISimpleType>>'。类型 'string[]' 缺少来自类型 'IMSTArray<ISimpleType>' 的以下属性:spliceWithArray、observe、intercept、clear 和 4 more.ts(2322)
这是一个恼人的错误。我可以通过这样分配来修复它:(self as any).stores = stores但我想停止对我的代码进行黑客攻击。
问题是为什么我会收到这个错误?是否有另一种方法可以分配给 mobx-state-tree 中的数组类型?
我在 mobx-state-tree 中找不到更详细的使用数组的文档。有人知道吗?