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