InstanceType<T>,该工具类型能够获取构造函数的返回值类型,即实例类型。示例如下:
class C {
x = 0;
}
type T0 = InstanceType<typeof C>; // C
type T1 = InstanceType<new () => object>; // object
type T2 = InstanceType<any>; // any
type T3 = InstanceType<never>; // any
type T4 = InstanceType<string>; // 编译错误
type T5 = InstanceType<Function>; // 编译错误
运行结果:
酷客网相关文章:
评论前必须登录!
注册