1 认识Flow

认识 Flow 随笔 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

2.为什么用Flow

认识 Flow 随笔 第2张

3.Flow的工作方式

通常,类型检查分为2种方式:

  认识 Flow 随笔 第3张

  认识 Flow 随笔 第4张

3.1类型判断

认识 Flow 随笔 第5张

 
认识 Flow 随笔 第6张 
 

认识 Flow 随笔 第7张

3.1类型注释

认识 Flow 随笔 第8张

 

/*@flow*/

function add(x, y){
  return x + y
}

add('Hello', 11)

认识 Flow 随笔 第9张

/*@flow*/

function add(x: number, y: number): number {
  return x + y
}

add('Hello', 11)

认识 Flow 随笔 第10张

/*@flow注释数组*/

var arr: Array<number> = [1, 2, 3]

arr.push('Hello')

认识 Flow 随笔 第11张

/*@flow注释类和对象*/

class Bar {
  x: string;           // x 是字符串
  y: string | number;  // y 可以是字符串或者数字
  z: boolean;

  constructor(x: string, y: string | number) {
    this.x = x
    this.y = y
    this.z = false
  }
}

var bar: Bar = new Bar('hello', 4)

var obj: { a: string, b: number, c: Array<string>, d: Bar } = {
  a: 'hello',
  b: 11,
  c: ['hello', 'world'],
  d: new Bar('hello', 3)
}

认识 Flow 随笔 第12张

认识 Flow 随笔 第13张

/*@flow*/

var foo: ?string = null

认识 Flow 随笔 第14张

官方文档地址

 

 4.Flow在Vue.js源码中的应用

认识 Flow 随笔 第15张

认识 Flow 随笔 第16张

认识 Flow 随笔 第17张

总结

认识 Flow 随笔 第18张

 

 

 

 

 

  

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄