dotcom-rendering icon indicating copy to clipboard operation
dotcom-rendering copied to clipboard

Enable `noUncheckedIndexedAccess` in DCR

Open OllysCoding opened this issue 3 years ago • 1 comments

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

OllysCoding avatar Aug 12 '22 12:08 OllysCoding

This would require a lot of refactoring in DCR: image

OllysCoding avatar Aug 12 '22 12:08 OllysCoding

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

mxdvl avatar Sep 22 '22 09:09 mxdvl