1: let a: Record<string, any> | null = {};
2: a['b'] = 2;
Encountered the
TS2531: Object is possibly 'null'
error on Row 2 despite having an initial value.
To address this issue, the code was updated as follows:
1: let a: Record<string, any> | null = {};
2: if (a) {
3: a['b'] = 2;
4: }
The inclusion of the if
condition is actually unnecessary since a
has the value {}
.
It is only added for tslint compliance. Is there a way to eliminate this unnecessary if
condition?