|
|
|
|
|
by zcesur
2050 days ago
|
|
Say you'd like to have an interface for things that are 'mappable'. For example, for arrays we could write: interface Mappable<Array> {
map<A, B>(f: (a: A) => B, fa: Array<A>): Array<B>
}
Likewise, for `Promise`s we could write: interface Mappable<Promise> {
map<A, B>(f: (a: A) => B, fa: Promise<A>): Promise<B>
}
But in order to generalize this interface to an arbitrary type constructor such that `F: * -> *`, we would need to write interface Mappable<F> {
map<A, B>(f: (a: A) => B, fa: ?): ?
}
which is not possible in TypeScript since it does not support higher-kinded types or type parameters that take type parameters or parametrized modules. |
|