// @flowconsta1: number =NaN;// NaN Infinity 0consta2: string ='';consta3: boolean =true;//true falseconsta4:null=null;consta5:void=undefined;consta6: symbol =Symbol();
其他类型
// 数组类型constarr1: Array<number>=[1,2,3];constarr2: number[]=[1,2,3];constarr3:[number, string]=[1,'1'];// 元组// 对象类型constobj1:{key1: number,key2: string}={key1:1,key2:'1'};constobj2:{key1?: number,key2: string}={key2:'1'};const obj3 ={};constobj4:{[string]: string }={};// 函数类型functionf1(callback:(string, number)=>void){callback('1',1);}// 字面量类型const a:'a'='a';// 联合类型consta1:'a'|'b'|'c'='a';
type TypeFlow = string | number;consta2: TypeFlow =1;// maybe类型const a3 ?number =null;// Mixed & Any 类型 都可以接受任意类型的值 但Mixed是强类型 Any是弱类型functionf1(value: Mixed){if(type of value ==='string'){
value.substr(1);}if(type of value ==='nubmer'){
value*value;}}functionf2(value: Any){
value.substr(1);
value*value;}