facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.09k stars 1.86k forks source link

Flow thinks "arguments" is an array? #8519

Open olleharstedt opened 4 years ago

olleharstedt commented 4 years ago

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(() => {
  });
}
Brianzchen commented 4 years ago

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

olleharstedt commented 4 years ago

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

Brianzchen commented 4 years ago

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

olleharstedt commented 4 years ago

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

Brianzchen commented 4 years ago

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 😅

olleharstedt commented 4 years ago

Yeah, I can check. Thanks!