首页 > 其他 > 详细

TS 限制类本身的基类

时间:2021-04-11 10:48:57      阅读:28      评论:0      收藏:0      [点我收藏+]
class Base {
  prop = null;
}

class Derived extends Base {
  derived = null;
}

class Another {
  another = null;
}

function fn(someClass: { prototype: Base }) {
  someClass;
}

// ok
fn(Base);
fn(Derived);

// 类型“typeof Another”的参数不能赋给类型“{ prototype: Base; }”的参数。
//   属性“prototype”的类型不兼容。
//     类型 "Another" 中缺少属性 "prop",但类型 "Base" 中需要该属性。ts(2345)
fn(Another);

TS 限制类本身的基类

原文:https://www.cnblogs.com/the-nightmare-x/p/14642982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!