Flow
CTO & Co-Founder
Nadav Leshem
Jolt.us
npm install --save-dev \
flow-bin\
babel-plugin-transform-flow-strip-types
touch .flowconfig
// @flow
function add(num1: number, num2: number): number {
return num1 + num2;
}
let myObject: {foo: string, bar: number} =
{foo: "foo", bar: 0};
let myMap: {[id:string]: number} = {};
myMap["sam"] = 10;
let array: number[] = [1, 2, 3.14, 42];
let array2: Array<string> =
["an alternate", "syntax", "for arrays"];
let tuple: [string, number, boolean] =
["foo", 0, true];
class MyClass {
foo: string;
constructor(foo: string) {
this.foo = foo;
}
bar(): string {
return this.foo;
}
}
function identity<T>(obj: T): T {
return obj;
}
class Container<T> {
obj: T;
constructor(obj: T) {
this.obj = obj;
}
}
const dc: Container<Date> =
new Container(new Date());
let o: ?string = null;
type U = number | string;
type BinaryTree =
{ kind: "leaf", value: number } |
{ kind: "branch",
left: BinaryTree,
right: BinaryTree }
type I = {foo: number} & {bar: number};
let y: I = {foo: 1, bar: 2};
20.11.16
By nadav
20.11.16
- 1,124