Flow version:
Flow should not complain about deleting optional chained props
Flow complains about deleting optional chained props
Following code:
const ob1: {a?: number} = { a: 1 };
delete ob1?.a;
causes following error:
2: delete ob1?.a;
^ Cannot delete `ob1?.a` [1] because only member expressions and variables can be deleted.
References:
2: delete ob1?.a;
^ [1]
However, such delete expression is totally legal, and we even have an unit test validating that it works
@mvitousek it looks like you introduced this in https://github.com/facebook/flow/commit/c1cd46caec6f02eee15b0616b3c7a3610ed5a5f9
Is there a plan to fix this or at least bailout and not type-check when optional chaining?
It means I have to put a load of $FlowExpectError and it confuses developers into thinking delete and optional chaining don't work together
@lukeapage Thanks for tagging me, I'm actually working on improving Flow's optional chaining support right now, and I'll work on getting out a fix for this in the process.
This issue appears fixed in 0.112.0
Most helpful comment
@lukeapage Thanks for tagging me, I'm actually working on improving Flow's optional chaining support right now, and I'll work on getting out a fix for this in the process.