facebook / facebook/flow

Questions: libdefs vs flow files (syntax, differences, etc.)

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

Description

Is there a difference between libdefs and flow files? I think there is, the docs says "A libdef is a special file (...)"

This topic was a bit confusing for me, because in the docs this difference is not documented very well. Especially the "declare" keyword is very confusing. If there is a difference between "libdefs" and "simple Flow files" then there should be an example for how to use the "declare" keyword in simple Flow files as well.
In AVA there is a Flow file which contains the types for that project. It's like:

```
declare module.exports: {
( run: ContextualTest): void;
(name: string, run: ContextualTest): void;
....
};
```

While in RxJS it's like:

```
declare module 'rxjs' {
declare module.exports: {
Observable: typeof rxjs$Observable,
ConnectableObservable: typeof rxjs$ConnectableObservable,
Subject: typeof rxjs$Subject,
...
```

In RxJS, the module.exports is inside a module declaration (which probably makes sense - it seems for me that the libdefs has global scoping, so you have to declare a module to separate it from other modules' libdefs), and the second difference which I saw is the syntax in the exported object. In the typedef of Rx, a literal object syntax is used, while the Flow file of Ava uses some class-like syntax (?).

(I also don't know what happens if there are multiple module.export blocks in your Flow files inside the same package.)

The third interesting thing which I saw is the prefixing in libdefs. Like `package$SomeType`. Is it some kind of convention or...? Is it because of global scoping of libdefs?

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.