How to use flow type in Javascript

Issue #389

Prefer flow over TypeScript for simplicity

Javascript primitive types number and string are too general and do not express the domain objects. Because lack of type alias in Javascript, we can use flow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export type Centimeter = number
export type Color = string
export type ImageSource = number
export type Kilogram = number
export type Kilocalorie = number // 1 cal = 4.1840 J
export type Second = number
export type SecondsSince1970 = number
export type Minute = number
export type DateString = string // 2018-11-20
export type DateTimeString = string // 2018-11-20T00:00:00
export type YearWeekString = string // 201838

export type FunctionWithVoid = () => void
export type FunctionWithString = (string) => void
export type FunctionWithBoolean = (boolean) => void
export type FunctionWithNumber = (number) => void
export type JSONObject = any
export type JSONString = string
export type StringToString = any

export type Degree = number
export type Radian = number

export type Animal = 'cat' | 'dog' | 'cow'

Comments