函数参数及返回值
// 定义返回类型
function getTotal() :number{
}
// 无返回值
function getTotal():void {
}
// 返回值是never,函数永远无法执行完
1、 function test():never {
throw new Error()
console.log('hello') // 永远无法执行此语句
}
2、死循环
function test1():never{
while(true) {
console.log('hello')
}
}
// 参数类型是对象
// 1.普通的js写法
function test({one,two}) {
return one+two
}
const total = test({one:1,two:2})
// 2.ts的写法
function test({one,two}:{one:number,two:number}) {
return one+two
}
const total = test({one:1,two:2})