1

I'd like to specify a generic type as a generic parameter so that I can use it in the body without a specific type parameter. Here's an example:

import Immutable from 'immutable';

interface IThing<List = Array> {
  numbers: List<number>;
  strings: List<string>;
}

class ImmutableThing implements MyThing<Immutable.List> {
}

But of course Typescript doesn't like this, in multiple ways--for one thing, Immutable.List needs a type parameter, for another Array needs a generic parameter (and if I do something like List<T> = Array<T> it says "cannot find name T").

Is there a way to do what I want in Typescript?

Turner Hayes
  • 1,844
  • 4
  • 24
  • 38
  • You're looking for "higher kinded types" which are, unfortunately, not supported by TypeScript. See [the answer](https://stackoverflow.com/a/60008205/2887218) to the other question for more information. – jcalz Dec 24 '21 at 00:35
  • Ah, thanks! Didn't know it had a name. – Turner Hayes Dec 24 '21 at 11:31

0 Answers0