flow icon indicating copy to clipboard operation
flow copied to clipboard

Flow thinks "arguments" is an array?

Open olleharstedt opened this issue 4 years ago • 6 comments

Flow version: 0.137.0

Expected behavior

arguments is not exactly an array, and does not have function forEach.

Actual behavior

No warning for the following code:

function foo() {
  arguments.forEach(() => {
  });
}
  • Link to Try-Flow or Github repo: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swo44AKQgGjACs6BrASjAG9UwwBDAJwDmmALYBTbPgDOAOnJ8Aoj1wALSpTYBeAHwcuYAL4sA3Kn1A

olleharstedt avatar Oct 31 '20 17:10 olleharstedt

Actually it's set to explicit any. You can do anything with it https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swo44AKQgGjACs6BrASjAG9UwwBDAJwDmmALYBTbPgDOAOgGj8AWVEBlOGIBq-Si1QBfIA

Brianzchen avatar Oct 31 '20 23:10 Brianzchen

Oh, OK. Can this be fixed to be more specific?

olleharstedt avatar Nov 01 '20 01:11 olleharstedt

It's defined here if you think it can be refined https://github.com/facebook/flow/blob/master/lib/core.js#L345

Brianzchen avatar Nov 01 '20 01:11 Brianzchen

This is the ts declaration:

interface IArguments {
    [index: number]: any;
    length: number;
    callee: Function;
}

Can it easily be translated to Flow?

https://github.com/microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L388-L392

olleharstedt avatar Nov 01 '20 21:11 olleharstedt

Maybe something like this?

Maybe you can first change the core.js locally to see if it works better, and then maybe check with others on discord to see if it's appropriate to make this change. I think this works but I'm not confident 😅

Brianzchen avatar Nov 01 '20 23:11 Brianzchen

Yeah, I can check. Thanks!

olleharstedt avatar Nov 02 '20 09:11 olleharstedt