facebook / facebook/flow

Is "declare" even necessary? What is it for anyway?

Open
#4,053 9 comments 2 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

I tried leaving out `declare` from my library definitions and it works just the same (I tried `declare type ` and `declare interface`, i.e. I tried removing the `declare` from all those statements and saw no difference).

The documentation is lacking about what it actually does and where to use it. On SO I found someone using `declare` to define something as global but _within his source code_. He then run into occasional somewhat random problems when it wasn't defined - I ventured the guess that if he defines something as global in the source instead of in a lib. definition the order in which source code files are parsed my matter and that global symbols should only be defined in lib. definitions. However, the documentation had nothing to clarify this issue.

But it seems anything in a library definition is global anyway (at least in my short test)? So what is `declare` used for anyway, what does it do?

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.