Using TypeScript


Using TypeScript? I suggest enabling this setting in tsconfig:

noUncheckedIndexedAccess

When this is enabled, TypeScript adds undefined to any un-declared field in the type.

The result? More type safety.

I have to check if an array index is defined before using it. 👍

I just enabled noUncheckedIndexedAccess on one of my client's projects. It exposed over 100 unsafe spots in the code.

We added checks for undefined, and in some cases, threw errors if the expected item isn't found.

Big win for stability and code clarity.

View original on X