Flux.ai was started around 3 years ago in TypeScript with the default compiler settings. If we could go back in time, there is one setting we would surely change: noUncheckedIndexedAccess. By default, this setting is false. Many people believe it should be true.
What does noUncheckedIndexedAccess do? By default, TypeScript assumes any array element or object property you access dynamically actually exists:
In the example above, the function will throw an error if the string is empty, because str[0] returns undefined and doesn't have a toUpperCase function. TypeScript doesn't warn you about that, regardless of whether strict mode is enabled or not. This is a huge hole in type safety.
The flag noUncheckedIndexedAccess will plug that hole and force you to deal with the possible undefined:
So, why can't we just turn on noUncheckedIndexedAccess? You can, but in a large codebase like that of Flux.ai, you are likely to get thousands of type errors. We had 2761 errors across 373 files! For one speedy engineer converting one file every minute, it would have taken 6+ hours of mind-numbing work to convert all 373 files.
The solution we describe here is how to smoothly convert your codebase with some simple heuristics and automation.
According to Wikipedia, a heuristic technique
is any approach to problem solving or self-discovery that employs a practical method that is not guaranteed to be optimal, perfect, or rational, but is nevertheless sufficient for reaching an immediate, short-term goal or approximation.
That is definitely true here.
The goal was to get the codebase compiling with the new flag, not to fix any bugs. The fixing can come later.
To that end, we intentionally added type assertions ! to suppress all new type errors from undefined types without changing the runtime behavior of the code.
Expanding the scope of replacements to preceding lines allowed us then to automate more fixes with few false positives.
The full script we ran on our codebase is below. Note: it did not fix all the errors. It fixed around 2400 out of 2761 errors, leaving around 100 files for us to fix by hand.
Pro-tip: when experimenting with the replacers and precede, you can simply reset your changes with git reset --hard HEAD (assuming you are working in a git repo).

A 2026 comparison of the top PCB design tools — Flux, Altium Designer, KiCad 10, and Fusion 360 — covering usability, features, collaboration, pricing, and the shift toward cloud-native, AI-assisted workflows.

A beginner-friendly guide to electronic circuit design, walking through schematics, key components, the schematic-to-PCB workflow, and how modern collaborative tools speed up hardware development.

A practical guide to high-current PCB design, covering trace width and copper weight, thermal management with vias and copper pours, layout best practices, and common mistakes to avoid in power electronics boards.

A guide to choosing PCB materials, comparing standard FR4 with advanced substrates like Rogers, PTFE, polyimide, and ceramics, and explaining how dielectric, thermal, and mechanical properties affect performance.

A practical guide to calculating PCB trace resistance, covering the core formula, how geometry affects resistance, worked examples, and design tips to minimize voltage drop and heat.

A practical guide to diagnosing and fixing PCB failures, covering common symptoms, a step-by-step debugging workflow, essential tools (multimeter, oscilloscope, logic analyzer, thermal camera), a pre-power-up checklist, and the design mistakes that most often lead to broken boards.

A practical guide to PCB impedance control, covering why it matters for signal integrity, the four physical variables that shape trace impedance, and how to enforce impedance targets from stackup planning through routing and fabrication.

A practical guide to reducing EMI in PCB design through grounding, return path control, shielding, and layout best practices. Covers EMC compliance with CISPR 32 and FCC Part 15.