Parametric types

#1

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

0 Likes

#2

Have you tried? I would say, why not.

0 Likes

#3

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