I want to safely access a property on a Union Type (all options are interfaces) set by external library(mobx).
Cannot call observe because:
Either property added is missing in IArrayChange [1] but exists in IArraySplice [2] in the first argument.
Or property added is missing in IObjectChange [3] but exists in IArraySplice [2] in the first argument.
142│ observe(thisContainer.items, (change: IArraySplice<any>) => {
143│ change.added.forEach((item: Item) => this.observeChanges(item));
145│ });
146│ }
147│
node_modules/mobx/lib/mobx.js.flow
356│ listener: (change: IArrayChange<T> | IArraySplice<T>) => void,
372│ listener: (change: IObjectChange) => void,
I have tried:
using conditionals to check whether
.addedexists before running change.added.iterator.if (change.added){&&if ('added' in change) {using a condition to check that the universally available property
typeis set tosplice. This should ensure that the property added is also available.change.type === 'splice' && change.added....
The docs suggest is typical to write conditions for type checks https://flow.org/en/docs/types/unions/ But I am unsure of the best way to do this w/ an external library's interfaces. Authoring functions such as Interface type check with Typescript feels heavier than I'd like for meeting the rules pre-commit type checker.
How should this be done?