Parametric types


Can we make a type be parametric, where the parameter of the type itself is is a parametric type?



Have you tried? I would say, why not.



Yes, you can certainly pass a bound parametric type as the parameter when defining a type, e.g.

type Foo mixes ParametricTypeA<ParametricTypeB<Bar>>

type ParametricTypeA<A>

type ParametricTypeB<B>

In addition, using the above example, you can enforce constraints on parameter A to ensure that it is a ParametricTypeB, but there is no way to reference the parameter B from the ParametricTypeA definition.

You can apply such a constraint like this:

type ParametricTypeA<A: ParametricTypeB>

But you cannot do something like this:

type ParametricTypeA<A: ParametricTypeB> {
  foo: B
1 Like