Optional chaining is a powerful feature when it comes to access data like
const options = cache.[server]?.[channel]?.[service]
Now when writing data we generally need to do something like
cache[server] ??= {}
cache[server][channel] ??= {}
cache[server][channel][service] = options
Is there something like optional chaining that make assignment like this lighter (maybe in one line)?
Something like :
cache[server]??{}:[channel]??{}:[service]=options
In this case adding {} or [] just after would permit to indicate what's expected to assign if nullish.
As proposed by @Bergi, the nearest way of doing this is to write like that:
((cache[server] ??= {})[channel] ??= {})[service] = options
cache[server]??{}:[channel]??{}:[service]=options- and this is what I call a readable, clean codeifstatements that create all the intermediate objects.