dotcom-rendering
dotcom-rendering copied to clipboard
Enable `noUncheckedIndexedAccess` in DCR
We should turn on noUncheckedIndexedAccess in our tsconfig.json: https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
/* Without 'noUncheckedIndexedAccess' */
const myArray: MyType = [];
const myVar = myArray[0];
// output: myVar: MyType
/* With 'noUncheckedIndexedAccess' */
const myArray: MyType = [];
const myVar = myArray[0];
// output: myVar: MyType | undefined
This is better for type safety & would make more sense in situations like: https://github.com/guardian/dotcom-rendering/pull/5694#discussion_r944357257
This would require a lot of refactoring in DCR:

Some work has gone into catching errors, and we now stand at 249 errors only. Most of them come from arrays of unknown length in Front slices.
See also:
- #5829
- #5777
- #5804
- #5806