ts函数类型


1. 直接声明

function add1 (x: number, y:number): number {

  return x + y

}

add(1, 2);

2. 变量声明

let  add2: (x: number, y:number) => number

add2 = (a, b) => a + b;

add2(1, 2);

3. 类型别名

type Add3: (x: number, y:number) => number

let add3 : Add3 = (a, b) => a+b

add3(1, 2);

4. 接口实现

interface Add4 {

  (x: number, y: number): number

}

let add4: Add4 = (a, b) => a+b

add4(1, 2);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM