Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: generic that extends a type with a generic (higher kinded types)

Tags:

typescript

Say I have an interface

interface Applicative<T> {}

Now I want to define a function f that:

  • takes a function and takes a type U extending an Applicative wrapping Any
  • and returns an U wrapping a function

How do I define this in Typescript ?

 function f<U extends Applicative>(fn: Function, a: U<any>): U<Function>

is my naive attempt but this is not valid

like image 600
Bruno Grieder Avatar asked Nov 30 '15 08:11

Bruno Grieder


1 Answers

Unfortunately, typescript does not (yet?) implement higher kinded types.

See https://github.com/Microsoft/TypeScript/issues/1213 for details

like image 116
Bruno Grieder Avatar answered Sep 29 '22 13:09

Bruno Grieder