proposal-shorthand-improvements icon indicating copy to clipboard operation
proposal-shorthand-improvements copied to clipboard

How would this work with Optional Chaining?

Open itamark opened this issue 5 years ago • 7 comments

This is a really interesting proposal. But I think we should consider this proposal and its implications on this one. https://github.com/tc39/proposal-optional-chaining

I just worry about safety of accessing deeper properties in objects while defining an object like this.

If no optional chaining is present, and something in the chain is undefined, the entire value becomes undefined, but the key remains the last accessor:

const a = { o.x.z.y.w }
// o.x.z is undefined
// result: a = { w: undefined }

Kind of an implicit optional chaining?

Or, should an error be thrown in this case, because we're accessing y of undefined?

itamark avatar May 28 '19 11:05 itamark