There is a proposal to allow optional chaining assignments which would allow you to do:
obj?.someProp = 42;
It won't check for existence of someProp
, just obj
.
Proposal: https://github.com/tc39/proposal-optional-chaining-assignment
It is implemented in babel, so you could use that already if transpiling.