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

# #!/JoePea (6 months 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 (6 months ago)

I was hoping to avoid things like

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


# Jordan Harband (6 months ago)
# #!/JoePea (3 months ago)

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