Last active
September 26, 2017 07:52
-
-
Save lazyTai/078ce54c8af6d9cf1e6bc47bbb9f3d80 to your computer and use it in GitHub Desktop.
flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*@flow*/ | |
var str = 'hello fuck all you work!'; | |
console.log(str); | |
/* | |
.babelrc | |
{ | |
"presets": ["flow"], | |
"plugins": [ | |
"transform-flow-strip-types", | |
] | |
} | |
*/ | |
/*install | |
cnpm isntall babel-preset-flow babel-plugin-transform-flow-strip-types -D | |
//what a fucking long shit | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
// Type Annotations | |
// Learn how to add type annotations to your code | |
/*Adding type annotations is an important part of | |
your interaction with Flow. | |
Flow has a powerful ability to | |
infer the types of your programs. | |
The majority of your code can rely on it. | |
Still, there are places where you’ll want to add types. | |
Imagine the following concat function | |
for concatenating two strings together.*/ | |
/*function concat(a:string,b:string){ | |
return a+b | |
} | |
var a=concat("fuck",111) | |
console.log(a)*/ | |
// Primitive Types | |
// Booleans | |
// Strings | |
// Numbers | |
// null | |
// undefined (void in Flow types) | |
// Symbols (new in ECMAScript 2015, not yet supported in Flow) | |
// true; | |
// "hello"; | |
// 3.14; | |
// null; | |
// undefined; | |
var cc=console; | |
/*var a=new Boolean(false); | |
var b=new String('world'); | |
var c=new Number(123.23423) | |
cc.log(a) | |
cc.log(b) | |
cc.log(c)*/ | |
/* | |
run result | |
babel-node .\fuck\type_annotations.js | |
[Boolean: false] | |
[String: 'world'] | |
[Number: 123.23423] | |
*/ | |
/*function method(x:number,y:string,z:boolean){ | |
cc.log(x) | |
cc.log(y) | |
cc.log(z) | |
} | |
method('123','dfgfd','sdfsdf')*/ | |
// Maybe types | |
/*function maybe(value:?string){ | |
cc.log(value) | |
return value | |
} | |
maybe(123471234)*/ | |
// Function parameters with defaults | |
/*function default11(x:string="default string"){ | |
cc.log(x) | |
return x; | |
}*/ | |
// cc.log(default11()) | |
// Using these with union types is powerful: | |
/*you only can use flew world*/ | |
function only1(name:'success'|'waring'|'danger'){ | |
switch(name){ | |
case "success":return "fuckq1"; | |
case "waring":return "fuckq2"; | |
case "danger":return "fuckq3" | |
} | |
} | |
cc.log(only1('waring')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
// Type Annotations | |
// Learn how to add type annotations to your code | |
/*Adding type annotations is an important part of | |
your interaction with Flow. | |
Flow has a powerful ability to | |
infer the types of your programs. | |
The majority of your code can rely on it. | |
Still, there are places where you’ll want to add types. | |
Imagine the following concat function | |
for concatenating two strings together.*/ | |
/*function concat(a:string,b:string){ | |
return a+b | |
} | |
var a=concat("fuck",111) | |
console.log(a)*/ | |
// Primitive Types | |
// Booleans | |
// Strings | |
// Numbers | |
// null | |
// undefined (void in Flow types) | |
// Symbols (new in ECMAScript 2015, not yet supported in Flow) | |
// true; | |
// "hello"; | |
// 3.14; | |
// null; | |
// undefined; | |
var cc=console; | |
/*var a=new Boolean(false); | |
var b=new String('world'); | |
var c=new Number(123.23423) | |
cc.log(a) | |
cc.log(b) | |
cc.log(c)*/ | |
/* | |
run result | |
babel-node .\fuck\type_annotations.js | |
[Boolean: false] | |
[String: 'world'] | |
[Number: 123.23423] | |
*/ | |
/*function method(x:number,y:string,z:boolean){ | |
cc.log(x) | |
cc.log(y) | |
cc.log(z) | |
} | |
method('123','dfgfd','sdfsdf')*/ | |
// Maybe types | |
/*function maybe(value:?string){ | |
cc.log(value) | |
return value | |
} | |
maybe(123471234)*/ | |
// Function parameters with defaults | |
function default11(x:string="default string"){ | |
cc.log(x) | |
return x; | |
} | |
cc.log(default11()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment