Stream: how can I introduce annotation of a local / global variable?

If I have a process.browser variable in my code, how can I annotate it?

+4
source share
1 answer

You can declare a variable process:

// @flow

declare var process: { browser: number }

const foo = process.browser * 3

Here is an example of this in action: https://flow.org/try/#0PTAEAEDMBsHsHcBQiAmBTAxtAhgJzaAG56gAOusGaAztQFygDeoARhfNWrgwHYCuAWxZdQAX2QZYPagBdQkWLFABeGaSiqqqiqzqqiq

In this example, a global variable is declared locally in the file that uses it, however it may be more ideal to declare it globally through a library definition. Following this route, it will be automatically determined for each file.

, <PROJECT_ROOT>/flow-typed/process.js, . , .

declare var process: { browser: number }
+5

Source: https://habr.com/ru/post/1678539/


All Articles