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 via stitching in PCB design -- what it is, why it improves EMI, signal integrity, and thermal performance, and where to place stitching vias. Includes spacing rules (like lambda/20), design guidelines, common mistakes to avoid, and how Flux can automate stitching via placement.

A guide to PCB component selection, covering electrical specs, footprints, thermal performance, sourcing, and best practices for picking parts that ship reliably.

A guide to PCB design reviews, covering schematic, layout, and DFM checks engineers use to catch errors early and ship more reliable boards.

A guide to creating and managing PCB footprint libraries, covering IPC standards, pad sizing, validation workflows, and best practices for reliable land patterns.

A guide to PCB schematic best practices, covering organization, symbols, labeling, and readability tips for clean, maintainable circuit diagrams.

A guide to flexible PCB design, covering materials, stackups, bend radius, and layout best practices for wearables, medical devices, and other compact electronics.

A beginner-friendly guide to reading PCB schematics, covering common symbols, nets, and how to follow signal flow through a circuit diagram.

An overview of collaborative PCB design, showing how cloud-native tools, real-time editing, and shared libraries are reshaping modern hardware team workflows.