facebook / facebook/flow

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

Aperta
#3,672 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.