Flow: delete check incompatible with optional chaining

Created on 2 Oct 2019  路  3Comments  路  Source: facebook/flow

Flow version:

Expected behavior

Flow should not complain about deleting optional chained props

Actual behavior

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

bug needs triage

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.

All 3 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Beingbook picture Beingbook  路  3Comments

funtaps picture funtaps  路  3Comments

ghost picture ghost  路  3Comments

jamiebuilds picture jamiebuilds  路  3Comments

glenjamin picture glenjamin  路  3Comments