facebook / facebook/flow

Declare a global which may or may not be present

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

Description

I'm trying to do something like `declare var foo? : string` such that `foo` is either a string, or doesn't exist at all as a global variable.

I can do `declare var foo : string | void` but that only gets me half way there; `console.log(foo)` will still typecheck. What I want is force the code to have to do a `typeof` check before using the variable, to make sure it exists.

Is there any way to declare a global that might not exist, in flow?

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.