【发布时间】:2019-09-05 10:37:28
【问题描述】:
我有这个基本模型。
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
& IStateTreeNode >'。 类型 'string[]' 缺少类型 'IMSTArray ' 中的以下属性:spliceWithArray、observe、intercept、clear 和 4 more.ts(2322)
这是一个令人讨厌的错误。我可以通过这样分配来修复它:(self as any).stores = stores 但我想停止对我的代码进行黑客攻击。
问题是为什么我会收到这个错误?在 mobx-state-tree 中是否有另一种方法可以分配给数组类型?
我在 mobx-state-tree 中找不到更详细的使用数组的文档。有谁知道吗?
【问题讨论】:
标签: typescript mobx tslint mobx-react mobx-state-tree