JavaScript 内核第 5 / 5 章
内置工具类型
使用标准工具类型完成常见的类型变换。
ts内置工具
interface IFunc {
name: string;
(this: { name: string }, num: number): void;
}
const printNumber: IFunc = function (this, num) {
console.log(num);
};
printNumber.name = "print";
//获取函数的类型
type printType = typeof printNumber;
//ThisParameterType获取这个类型的this
type This = ThisParameterType<printType>;
//提取除了this以外的类型
type pureType = OmitThisParameter<printType>;
//绑定上下文的方法
ThisType<printType>;