I have a simple model that I am working with.
const info = types.model({
name: types.string,
age: types.number,
hobbies: types.array(types.string)
}).actions(self => ({
setName(name: string) {
self.name = name
},
setAge(age: number) {
self.age = age
},
setHobbies(hobbies: string[]) {
self.hobbies = hobbies // <<< the lint error is on this line
}
}))
When trying to assign an array, I encounter the following TS Lint error:
Type 'string[]' is not assignable to type 'IMSTArray<ISimpleType> & IStateTreeNode<IArrayType<ISimpleType>>'. Type 'string[]' is missing the following properties from type 'IMSTArray<ISimpleType>': spliceWithArray, observe, intercept, clear, and 4 more.ts(2322)
This error is frustrating. Although I can work around it by using (self as any).hobbies = hobbies
, I am looking for a cleaner solution to address this issue.
I am wondering why exactly this error occurs and if there is a proper method to assign values to an array type in mobx-state-tree?
I have searched for more detailed documentation on handling arrays in mobx-state-tree but haven't found anything thorough. Does anyone have insights or resources on this topic?