facebook / facebook/flow

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

Offen
#3,672 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
question
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.