Turn on noUncheckedIndexedAccess
By default items[0] is typed as Item, even when the array is empty. The runtime disagrees.
{ "compilerOptions": { "noUncheckedIndexedAccess": true } }With it on, an index read is Item | undefined and you have to handle the miss. It is noisy for a week on an old codebase and it finds real bugs on day one. New projects should start with it.
typescript