Optional chaining with operators

We already have that situation with unary operators: as described in the thread Optional chaining on prefix operators, optional chaining works with postfix operators x?... but not prefix operators ...x?.

I don’t think it’s surprising to say, “optional chaining takes an optional on the left and a function on the right”.

• • •

My actual use-case for this, besides a general sense that it ought to work for consistency, is dynamic casting:

(t as? T)?.foo()   // valid
(t as? T)? == u    // error

I’d like to be able to write the latter.

1 Like