typeof
typeof 在类型上下文中使用,用于获取一个变量或者属性的类型,只能对标识符和属性使用
1  | let s="hello";  | 
1  | let shouldContinue:typeof msgbox("hello");  | 
要获取msgbox(“hello”)返回值的类型,正确写:
1  | ReturnType<typeof msgbox>  | 
ReturnType
你传入一个函数类型,ReturnType
1  | type Predicate=(x:unknown)=>boolean;  | 
值(values)和类型(types)并不是一种东西,为了获取值f也就是函数f的类型,需要使用typeof,而ReturnType
1  | function f(){  | 
对enum类型使用typeof
在TypeScript中,在具体运行时,enum类型会被编译成对象
1  | enum UserResponse {  | 
对应编译的JavaScript
1  | var UserResponse;  | 
1  | console.log(UserResponse);  | 
1  | type result = typeof UserResponse;  | 
一般搭配keyof用于获取属性名的联合字符串
1  | type result=keyof typeof UserResponse;  | 
参考:
https://ts.yayujs.com/handbook/TypeofTypeOperator.html#%E5%AF%B9-enum-%E4%BD%BF%E7%94%A8-typeof
https://www.typescriptlang.org/docs/handbook/2/typeof-types.html