Visual LabINTERACTIVE LEARNING
JavaScript 内核第 5 / 5 章

内置工具类型

使用标准工具类型完成常见的类型变换。

TypeScript泛型类型体操
进阶预计 48 分钟查看源文 ↗

ts内置工具

详见:TypeScript 内置工具详谈


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>;