typescript - TypeScript 泛型:不满足约束
问题描述
我正在尝试制作打字稿以警告错误的类被解释为泛型类型参数。
预期结果:
class A { }
class B extends A { }
class C<T extends A> { }
const instance1 = new C<A>(); // error: wrong type
const instance2 = new C<B>(); // success: inherited type
实际结果:
class A { }
class B extends A { }
class C<T extends A> { }
const instance1 = new C<A>(); // success: but the type is wrong
const instance2 = new C<B>(); // success: inherited type
解决方案
推荐阅读
- dart - 我怎样才能让 BottomNavigationBar 粘在键盘颤动的顶部
- winapi - 是否可以按 FIFO 顺序将自定义消息放入 win32 消息队列中?
- python - 在 TensorFlow 对象检测 API 中获取类和概率
- c++ - 用于双链接结构的c ++堆排序
- javascript - 如何将 chai-as-promised 与 Typescript 一起使用?
- excel - Excel 数据透视表 - 如何排列字段以对字段求和,同时忽略来自另一个不相关字段的重复行
- json - 在 QJSonArray 中搜索项目
- javascript - 将 SnapshotChanges 与 CombineLatest 一起使用
- java - Java 无法推断“类”<> 的类型参数
- php - PHP 中的 iCloud Web 服务服务器到服务器身份验证