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 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.

A step-by-step guide to designing accurate PCB footprints — covering pads, silkscreen, courtyards, IPC-7351 density levels, origin setup, and common mistakes to avoid.

A practical guide to PCB grounding techniques — ground planes, return paths, star grounding, and analog/digital partitioning — with best practices for reducing noise and improving signal stability.

A practical guide to designing multilayer PCB stackups for signal integrity, EMI control, and stable power delivery. Covers layer types, controlled impedance, common mistakes, and how modern tools simplify the process.

A look at how AI is reshaping PCB design by automating routing, placement, and signal integrity checks so engineers can focus on architecture and higher-level decisions.