【发布时间】:2020-11-17 18:51:06
【问题描述】:
昨天我问了这个问题How to restrict the typescript T to be only camplex object
现在我想知道如何实际做相反的事情?
class abstract MyClass<T> { }
我只想允许原始类型(字符串、布尔值等),例如:
class MyOtherClass extends MyClass<string> { } //<-- allowed
class MyOtherClass extends MyClass<IInterface> { } //<-- not allowed
实现这一目标的最佳方法是什么?
【问题讨论】:
标签: typescript typescript-generics