facebook/flow

Higher order type parameter support

xiaoxiangmoe opened this issue · 1 comments

Proposal

As we known, we can write higher order function in js

const makeTuple = x => y => [x, y]

Can we provide something like this in type level?

// define
type MakeTupleType <T> <U> = [T, U]
// use it
type MyTupleType = MakeTupleType<number><string>
// or some thing like 
type MyTupleType1 = MakeTupleType<number>
type MyTupleType2 = MakeTupleType1<string>

// define
const makeMyTupleFunction = <T> <U> (x: T, y: U) => [x, y]

// use it
const makeMyNumberStringTuple = makeMyTupleFunction<number><string>
const myTuple = makeMyTupleFunction(1, '')

// or some thing like 
const makeMyNumberAnyTuple = makeMyTupleFunction<number>
const myTuple = makeMyTupleFunction<string>(1, '')

Are there more concrete use cases other than these toy examples? Is there any important framework code that can be property typed, but will be otherwise impossible to declare its type without this feature?