美文网首页
前端小白成长之10--Flow

前端小白成长之10--Flow

作者: Clover园 | 来源:发表于2020-05-20 20:55 被阅读0次

一.安装flow-bin

安装和移除注解

二、原始类型 string number boolean null undefined (这里用的void) symbol


原始类型

三.数组类型


数组类型
四.对象类型

属性后面❓,意思可以定义可以不定义,可以是其他类型,就是不能为null


image

五.函数参数类型,返回值类型

一般写在fun():string{}意思返回值要为string,回调函数里面注解看下图

image

六.特殊类型

类型前面❓,意思还可以是undefined或者null


image

七.mixed any


image
//@flow
function sum(a: number, b: number) {
    return a + b;
}
sum(100, 100);

const a: string = 'qw';
const b: boolean = true;
const c: null = null;
const d: void = undefined;
const e: number = 0;
const f: symbol = Symbol();

const arr1: Array<number> = [1, 2, 3];
const arr2: number[] = [1, 2, 3, 4];
const arr3: [string, string, number] = ['1', '2', 2];

const obj1: { a: number, b: string } = { a: 1, b: '2' };
const obj2: { a?: number, b: string } = { b: '2' };
const obj3: { [string]: string } = {};
obj3.foo = 'foo';
obj3.bar = 'bar';


function getData(a:string) :void{
    //void就是无返回值,或者为undefined
}
getData('12');

function foo(callback: (string, number) => string) {
    callback('string',120);
}
foo(function (string, number) { return 'haha' });

const as: string | boolean | number = false;
type _twoType = string | number;//type定义好备用
const des: _twoType = 100;
const ert: ?number = null//2//undefined

const element: HTMLElement | null = document.getElementById('app');

相关文章

网友评论

      本文标题:前端小白成长之10--Flow

      本文链接:https://www.haomeiwen.com/subject/qfloohtx.html