Flow: No error when reassigning variable in a closure

Created on 8 Mar 2019  路  1Comment  路  Source: facebook/flow

Flow version: 0.94.0

Expected behavior

Since flow won't know whether the closure is called or not, I would expect the type of a to be string | number

Actual behavior

Type of a is string

Flow try

function myFunc(): string {
  let a = "a string";

  [1].forEach(() => {
    a = 2;
  });

  return a; // a is string
}
soundness bug

Most helpful comment

Yikes. This is pretty scary. Thanks for pointing this out. I think we have a fix in the works that should be out in one of the next versions.

>All comments

Yikes. This is pretty scary. Thanks for pointing this out. I think we have a fix in the works that should be out in one of the next versions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tp picture tp  路  3Comments

ctrlplusb picture ctrlplusb  路  3Comments

mjj2000 picture mjj2000  路  3Comments

damncabbage picture damncabbage  路  3Comments

cubika picture cubika  路  3Comments