- 检测变量或对象属性的类型,无法查询其他形式的类型(比如:函数调用的类型)
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)