Maroš Beťko
Maroš Beťko

Reputation: 2339

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 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. 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.

Usage of said class would look something like this:

class Impl implements Interface { a: string; }
type Boo = Foo<Goo<Impl>>;

Upvotes: 0

Views: 60

Answers (1)

Matthew Layton
Matthew Layton

Reputation: 42390

You could just do this

class Foo<T extends Goo<Interface>> {}

Upvotes: 1

Related Questions