1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| function add(x: number, y: number): number { return x + y } let add1: number = add(10, 20)
let myAdd: (x: number, y: number) => number = function (x: number, y: number): number { return x + y } let myAdd1= function (x: number, y: number): number { return x + y }
let getFullname= function (firstname: string, lastname?: string): string { if(lastname){ return firstname + lastname }else{ console.log(123); } } getFullname('he')
// 剩余参数 function info(x: string, ...args: string[]) { console.log(x, args) } info('abc', 'c', 'b', 'a') //abc [ 'c', 'b', 'a' ]
|