Ramonda

lens-path-through-a-gap

This fails the run. Where it is wrong about your code, // ramonda-check-ignore <reason> on the line says so, and the reason is printed on every run.

Reported when a focusOn write walks through a hop the types say may be null or undefined, which only the LAST hop creates.

The framework reports the same fault while running, as RML001 — but only once the line actually runs. This is the same fault proved from the source instead.

A lens path CREATES its last hop and walks every hop before it. So this is safe:

focusOn(state).get("profile").set({ name: "Ada" })       // creates the profile

and this is not, when profile may be missing:

focusOn(state).get("profile").get("name").set("Ada")     // walks through it

There are two ways out, and which one is right depends on what a missing value means:

Prove it is there. If the code already runs only when it is, say so and the report stops:

if (state.profile) focusOn(state).get("profile").get("name").set("Ada");

Write the whole object. If a missing value should be filled in, do it in one hop:

focusOn(state).get("profile").merge({ name: "Ada" })

Reported from the ANNOTATION as written — profile?: Profile or profile: Profile | null. A type this cannot read from the source says nothing, and nothing is reported for it.

Next