【TypeScript】四、数组与函数重载
  1. 数组
let arr: number[] = [1, 2, 3, 4,]
let arr1: string[] = ["hello", "world"]
let arr2: boolean[] = [true, false]
let arr3: any[] = [1, '1', true]
let arr4: Array<number> = [1, 2, 2,]
console.log(arr)
console.log(arr1)
console.log(arr2)
console.log(arr3)
console.log(arr4)
[ 1, 2, 3, 4 ]
[ 'hello', 'world' ]
[ true, false ]
[ 1, '1', true ]
[ 1, 2, 2 ]
  1. 函数重载
function fn(a:number, b:number):number
function fn(a:string, b:string):string
function fn(a:any, b:any):any {
    return a+b
}
let a = fn(1, 1)
let b = fn("1", "1")
console.log(a, b);
posted on 2022-07-05 16:52  仓鼠不爱吃辣条  阅读(38)  评论(0)    收藏  举报

页尾

页尾

页尾

页尾

页尾

页尾

页尾