Currently, I'm in the process of structuring my new project using TypeScript and MobX-state-tree. However, I've encountered a minor issue while working on it. Specifically, within the service function, I need to loop through the MST array stored in one of my models.
Here is an example of the model in question:
export const ValueHolder = types.model("ValueHolder", {
identifier: types.maybeNull(types.union(types.number, types.string))
});
export const Results = types.model("Results", {
locations: types.array(ValueHolder)
});
As for the service function:
sendLocationNotification(locations: ValueHolderArrayType) {
locations.forEach(function (locationResult) {
});
}
The TypeScript types are defined as follows:
export type ValueHolderArrayType = IArrayType<typeof ValueHolder>;
export type ValueHolderType = Instance<typeof ValueHolder>;
However, I am encountering
TS2339: Property 'forEach' does not exist on type 'ValueHolderArrayType'
.
I have noticed that IArrayType extends from IType, which includes IMSTArray, extending from the root js Array typing, thus implying it should have the forEach signature. Despite my efforts to identify the mistake after thorough research, I still believe the error lies in my typing setup.
If possible, could you provide me with guidance on how to correctly define typings so that I can effectively iterate over the MST array?
Thank you.