Why can't the left-hand side of an assignment expression use optional chaining?

# #!/JoePea (4 years ago)

This is perfectly fine:


but this is not:

this.foo?.bar?.baz = 123

Why is that not allowed, but function calls are?

I find myself often wanting to do assignments like that. When I am auto-completing things in VS Code (TypeScript), it automatically and awesomely inserts the ? characters, only to fail once I write the assignment part.


# #!/JoePea (4 years ago)

I was hoping to avoid things like

const baz = this.foo?.bar?.baz
if (baz) baz.lorem = 123


# Jordan Harband (4 years ago)
# #!/JoePea (3 years ago)

There's a good number of upvotes for it. It would be nice. #!/JoePea