Wayne Maurer
Wayne Maurer

Reputation: 12581

How to specify generic type as a generic (higher kinded types)

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

Answers (2)

Bruno Grieder
Bruno Grieder

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

Aditya Singh
Aditya Singh

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

Related Questions