[英]Type inference of generic types
I was trying to make something like this work. 我试图做这样的事情。 The point is that I have some
Interface
, then a Goo
class that has one generic type that extends said interface. 关键是我有一些
Interface
,然后是一个Goo
类,该类具有扩展该接口的通用类型。
interface Interface { a: string; }
class Goo<T extends Interface> { props: T }
class Foo<T extends Goo<T["props"]>> {}
I would like to create a Foo
class that takes generic type that extends this generic Goo
. 我想创建一个
Foo
类,该类采用扩展此通用Goo
通用类型。 Problem is that Goo
expects a generic argument, which I tried to use the T["props"]
for, but the syntax checker is showing error that that type does not satisfy the interface. 问题是
Goo
需要一个通用参数,该参数我曾尝试使用T["props"]
,但是语法检查器显示该类型不满足接口的错误。
Usage of said class would look something like this: 所述类的用法如下所示:
class Impl implements Interface { a: string; }
type Boo = Foo<Goo<Impl>>;
你可以这样做
class Foo<T extends Goo<Interface>> {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.