Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazyTai/078ce54c8af6d9cf1e6bc47bbb9f3d80 to your computer and use it in GitHub Desktop.
Save lazyTai/078ce54c8af6d9cf1e6bc47bbb9f3d80 to your computer and use it in GitHub Desktop.
flow
/*@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
*/
// @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'))
// @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