Is there a way to set obj['a32']['a']=3232 without using if statement and without using ! to tell compiler to not check?
I tried using ?. but it throws The left-hand side of an assignment expression may not be an optional property access.(2779)
Playground: link
interface A{
[key:string]:{[key:string]:number};
}
const obj:A = {};
const k='a32';
if(!obj[k]){
obj[k]={};
}
obj[k]['a']=3232; // Object is possibly 'undefined'.(2532)
obj[k]?.['a']=3232; // The left-hand side of an assignment expression may not be an optional property access.(2779)
obj[k]!['a']=3232; // this works but never checks if obj['a32] is defined
if(obj[k]){
obj[k]['a']=3232;
}