flowjs/flow.js

Bug: Cannot use variable x because the declaration either comes later or was skipped.

Closed this issue · 1 comments

export type Order = {
  x: number;
  y: number;
}
a: Array<Order> = [];
f() {
    let a_i = this.a.slice(-1)[0];
    a_i.x += 1; // that's ok
    a_i.y -= 1; // that's ok
    assert( a_i.x - a_i.x < 1 );
    if (true) {
        assert(a_i.x < 1); // that's not okay? why?
        // "Flow Error: Cannot use variable a_i because the declaration either comes later or was skipped."
        let a_i = this.a.pop(); // I do realize it's bad practice to declarate it again 
        // but supposly that's not agsinst ES6 standards 
        // if it's not - the error message is ambiguous and misleading. 
    }
}

see screenshot https://www.dropbox.com/sh/m6vm307dj4267dc/AAD_AAlqUS6kyXzEeqb1t_z4a?dl=0

I think I misunderstood JS standard for that, sorry.