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;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM