ts 类型断言

定义:类型断言好比其它语言里的类型转换,但是不进行特殊的数据检查和解构;

语法:<类型>值 或者 值 as 类型

举例说明

1.<类型>值 

let someValue: any = "this is a string"; let strLength: number = (<string>someValue).length;

2.值 as 类型

let someValue: any = "this is a string"; let strLength: number = (someValue as string).length;

posted @ 2020-01-06 17:49  Mir.zhao  阅读(3330)  评论(0编辑  收藏  举报