facebook / flow

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

Top level exports #9136

Closed StefanoBalocco closed 2 months ago

StefanoBalocco commented 2 months ago

I'm trying to convert some typescript code to flow but there is a part that seems invalid in flow:

class foo {
    bar() {

    }
}

if( typeof exports === 'object' ) {
    exports.foo = foo;
}

Flow version: 0.232

Expected behavior

No error

Actual behavior

Exports can only appear at the top level [invalid-export]

SamChou19815 commented 2 months ago

TypeScript probably shouldn't accept this code, since it's too dynamic to analyze the signature of the module. I think in this case, TS might think that the code is a script rather than a module, so it has more relaxed checks.