Encountering a potential issue with strictNullChecks in TypeScript (v. 3.2.1):
interface IData {
data?: { payload: string };
}
const list: IData[] = [];
const index: number = 0;
//testing a
if (list[index].data)
list[index].data.payload = "a";
//testing b
const item = list[index].data;
if (item)
item.payload = "a";
Why does "test a" result in a warning "object is possibly undefined" while "test b" does not? Is there a specific rationale for this behavior?