How to create a type of fixed length in a stream

I want to create a type that represents 2 character ISO country codes. Is there an easy way to create a type definition for them (or any other element of a fixed length)?

Of course, one approach would be listing with a list of all the possible

type CountryCode = "AX" | "AL" | "DZ" | ...

But I would like something simpler, just imposing 2-character strings.

Do I need to use dynamic type tests ?

+4
source share
1 answer

No, Flow doesn't have that feature. In fact, it does not have any dependent types, except for other types containing separate values.

, if (countryCode.length === 2) { ... }, , JS, Flow countryCode if, .

if (countryCode !== null) Flow , countryCode if .

, , 26 * 26 = 676 A Z: "AA", "AB",..., "ZY", "ZZ", .

+4

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


All Articles