- Flow开发工具插件 Flow-lanuage(vs code 商店中搜索)
https://flow.org/en/docs/editors/ 关于lflow的插件 - Flow原始类型
//flow原始类型 const a: string = 'foo' const b: number = Infinity // NaN // 100 const c: Boolean = true // false const d: null = null const e: void = undefined const f: symbol = Symbol //Flow 数组类型 const arr1: Array<number> = [1, 2, 3, 4] const arr1: number[] = [1, 2, 3, 4] //元组 const foo: [String, Number] = ['foo', 100] //对象类型 const obj1 = { foo: string, bar: number} = { foo:'string', bar:100} const obj2 = { foo?: string, bar: number} = { bar: 100 } const obj3 = { [string]: string } = {} obj3.key1 = 'value1' obj3.key1 = 'value2' //函数类型 function foo (callback: (string, number) => void) { callback('string', 100) } foo(function (str, n) { }) //特殊类型 const a: 'foo' = 'foo' const type: 'success' | 'warning' | 'danger' = 'success' const StringOrNumber = string | number const b: StringOrNumber = 'string' //100 const gender: ?number = undefined const gender: number | null | void = undefined //mixed 和 any 都可以传入 string number boolean... //二者区别是,mixed 是强类型,安全,any 是若类型,使用不安全,少用,它存在的意义是为了兼容以前的旧代码 function passMixed (value: mixed) { if (typeof value === 'string') { value.substr(1) } if (typeof value === 'number') { value * value } } passMixed('string') passMixed(100) // =================== function passAny (value: any){ value.substr(1) value * value } passMixed('string') passMixed(100)
Flow文档网址
https://flow.org/en/docs/types/
https://www.saltycrane.com/cheat-sheets/flow-type/latest/
Flow使用
最新推荐文章于 2022-11-14 14:47:20 发布