OmitThisParameter<T>,该工具类型能够从类型T
中剔除this
参数类型,并构造一个新类型。在使用“Omit-ThisParameter<T>”
工具类型时需要启用“--strictFunctionTypes”
编译选项。示例如下:
/**
* --strictFunctionTypes=true
*/
function add(x: number): void {
console.log(x)
}
function f0(this: object, x: number) {}
function f1(x: number) {}
// (x: number) => void
type T0 = OmitThisParameter<typeof f0>;
// (x: number) => void
type T1 = OmitThisParameter<typeof f1>;
// string
type T2 = OmitThisParameter<string>;
const x: T0 = add;
const y: T1 = add;
const z: T2 = "coolcou.com";
console.log(x)
console.log(y)
console.log(z)
输出结果:
酷客网相关文章:
评论前必须登录!
注册