- 检测变量或对象属性的类型,无法查询其他形式的类型(比如:函数调用的类型)
console.log(typeof 'Hello world'); // 这种查询是错误的:无法查询其他形式的类型(比如:函数调用的类型) function add1(num1: number, num2: number) { return num1 + num2 } let ret: typeof add1(1, 2)
- 出现在类型注解的位置(参数名称的冒号后面)所处的环境就在类型上下文
let P = { x: 1, y: 2 } function formatPoint(point: { x: number, y: number }) { } // 等同于 // function formatPoint(point: typeof P) { } formatPoint(P)
最后
以上就是精明超短裙最近收集整理的关于TS中typeof的用法的全部内容,更多相关TS中typeof内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复