I am finding hard to use Flow. I understand that Array.find can return or be undefined.
So by reading this: github: Array.find on Array<{...}> raises
I did that and added void to the type to. However now I get the error:
Cannot get
stageMsg.msgbecause propertymsgis missing in null or undefined (see line 92).
Check code to see where the error is specifically.
I understand why it is giving me the error, there is no msg in undefined. what I don't know is how to solve this issue.
Here is the code:
type StageMsg = {
stage: number,
msg?: string
};
let stageMsg: void | StageMsg = this.stages.find(
(obj: StageMsg) => obj.stage === this.state.stage
);
msg = (
<Msg text={this.state.msg !== "" ? this.state.msg : stageMsg.msg} /> //<---- [Error here].
);