Reputation: 12581
In Typescript, is it possible to specify a generic type as generic? Specifically, I would like to be able to define a function signature as follows:
function events<T>(): T<Event>
However I am receiving the following error from the typescript compiler:
[ts] Type 'T' is not generic.
Upvotes: 13
Views: 1091
Reputation: 29814
"generic type as a generic": if I understand correctly what you are trying to achieve is to use higher kinded types.
This not (yet) possible in Typescript: see this
Upvotes: 12
Reputation: 16650
Change the definition as below:
function events<T>(): Event<T>
Read more about the syntax here: https://www.typescriptlang.org/docs/handbook/generics.html
Upvotes: -1