facebook / facebook/flow

[libdef] declare module auto-export is too much magic

Open
#3,119 3 comments 3 reactions 0 assignees View on GitHub
declarations
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I see this all the time... people (including me initially) are really confused about the export handling of `declare module`.

If I do this:

```
declare module 'mylib' {
declare type Foo = { bar: 'test' };
}
```

The type `Foo` will automatically be exported.
As soon as I use `declare module.exports: ...`, `declare var exports: ...` or `export type Other = ....`, flow will only export entities via the export mechanics.

IMO it should by default assume private scope and only export entities, which are explicitly exported (like ES6 or Node CJS do).

It causes a lot of confusion whenever someone submits `flow-typed` libdefs... people tend to use namespaces inside `declare module`, although they are using `declare module.exports` and just make libdefs hard to read (because of this `$npm$whatever$MyType` naming).

I wonder if the default behavior will be changed in the future?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.