December 2018
Intermediate to advanced
642 pages
15h 5m
English
The basic definitions of the previous section may be enough for plenty of code, but as you start working with more complex problems, you'll need some more advanced Flow features, and you may want to define types separately so that you can reuse them elsewhere. Due to this, in this and the following sections, we'll look at more advanced types.
In JS, it's common that a variable may have, at different times, different data types. For that situation, you can use union types:
// Source file: src/types_advanced.jslet flag: number | boolean;flag = true; // OKflag = 1; // also OKflag = "1"; // error: wrong typelet traffic: "red" | "amber" | "green"; // traffic is implicitly stringtraffic = "yellow"; // error: not allowedtype numberOrString ...
Read now
Unlock full access