Slack proposal: https://expensify.slack.com/archives/C01GTK53T8Q/p1717468504413819
Problem
We currently have crash occurring on production. The problematic code can be summarized with a minimal example:
type MyType = {
something: string;
};
const myArr: MyType[] = [];
// myItem is inferred to have type MyType, when really it is undefined
const myItem = myArr[42];
// No compiler error, but the app will crash
console.log(myItem.something);
As you can see, we unsafely indexed an array, and then assumed the result was defined. Then trying to access a property of undefined, we experience a crash.
Solution
Enable the noUncheckedArrayAccess TypeScript config. With that config enabled, the type of myItem is correctly inferred to MyType | undefined, and we get a compiler error when trying to access myItem.something, preventing the crash at compile time.
Issue Owner
Current Issue Owner: @adelekennedy
Slack proposal: https://expensify.slack.com/archives/C01GTK53T8Q/p1717468504413819
Problem
We currently have crash occurring on production. The problematic code can be summarized with a minimal example:
As you can see, we unsafely indexed an array, and then assumed the result was defined. Then trying to access a property of
undefined, we experience a crash.Solution
Enable the noUncheckedArrayAccess TypeScript config. With that config enabled, the type of
myItemis correctly inferred toMyType | undefined, and we get a compiler error when trying to accessmyItem.something, preventing the crash at compile time.Issue Owner
Current Issue Owner: @adelekennedy