类型断言

let someValue: any = 'this is a string'
// 类型断言方式一:
let strLength: number = (<string>someValue).length
// 类型断言方式二:【推荐使用这种方式】
let strLength: number = (someValue as string).length

 

posted @ 2020-12-04 22:06  ladybug7  阅读(175)  评论(0编辑  收藏  举报