Always check for null/undefined before accessing values or rendering UI instead of relying on non‑null assertions or unconditional usage. Prefer optional chaining and explicit guards in logic and conditional rendering in JSX.
Why: Non-null assertions (!) and unconditional rendering can cause runtime exceptions when data is absent. Explicit checks make intent clear and avoid crashes.
How to apply:
Replace ! assertions with optional chaining and guards:
Bad: let relationId = only(edge.data.relations)!.id;
Good: let relationId = only(edge.data.relations)?.id;
if (relationId) { /* use relationId */ }
Conditionally render components only when required data exists: