注解
一、函数体
1.1 普通函数
-
返回值为基础类型
function foo(x:number,y:number):number{
return x+y;
} -
返回值为
Promise
async function foo():Promise<number>{
return 1
}
1.2 字面量函数
-
语法一、直接注解
const foo : (x:number,y:number) => number = (x,y)=>{
return x+y;
} -
语法二、通过
type
注解-
标准写法
type Foo = {
(argu1: string, arug2: number) : number
};
const foo: Foo = function (argu1, argu2) {
return argu2;
}
-