I am doing the following object access. But TS complains that it may be undefined even when I check for it.
if (metrics[key0]) {
if (metrics[key0][key1]) {
[…]metrics[key0][key1]]);
}
}
=> Error TS2532 in line 2 and 4. Playground example: Click Me
When I change it to metrics[key0]?.[key1]
the error is gone. But why do I need that? In the if it cannot be null or undefined?
Edit: Please do not again mark this as duplicate of this. In that topic there is no check for null or undefined.