ReturnType TypeScript · 工具类型
从函数类型里抽出它最后带回来的类型,像看快递单上的"内件品名"。
怎么用
ReturnType<typeof 函数>
小例子
function 加(a: number, b: number) {
return a + b;
}
type 和 = ReturnType<typeof 加>;
类型检查结果
和 是 number
提醒:别忘了用 typeof 取函数类型
官方文档:https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← TypeScript全部词条