Thoughts about unification
declarefunctioncompose<T,U,V>(a: (x: T)=>U,b: (y: U)=>V): (x: )
Works fine today if you pass it in non-generic functions, but not for if you pass in generic functions.
However, gives bad results today for a generic function.
Ideally, you'd like to be able to use compose on higher-order functions like the following:
declarefunctioncompose<T,U,V>(a: (x: T)=>U,b: (y: U)=>V): (x: T)=>V;declarefunctionarrayToList<T>(x: Array<T>): List<T>;declarefunctionbox<U>(x: U): {value: U};compose(arrayToList,box)// <T>(x: Array<T>) => { value: List<T> }Idea: you want to float out the free type variables into the result type for whatever doesn't get unified.
You want to build up the inferences:
declarefunctioncompose<A,B,C>(a: (x: A)=>B,b: (y: B)=>C): (x: A)=>C;declarefunctionarrayToList<T>(x: Array<T>): List<T>;declarefunctionbox<U>(x: U): {value: U};compose(arrayToList,box);// A = Array<T>// B = List<T>// B = U// C = { value: U }You iterate on A, B, and C, finding new "truths" about the relationships between these type variables. For example, you can see that:
and then
But there are questions: how do you
Parameters type aliases
#26042
- Problem: you want to constrain this type to some function type.
- Otherwise you can get garbage.
- Thought: you kind of want something like
typeParameters<Textends(...args: (infer U))=>any>=U;
- Conclusion: we'll fix up the type an add it to the library.
Method parameter inference
#23911
Thoughts about unification
Works fine today if you pass it in non-generic functions, but not for if you pass in generic functions.
However, gives bad results today for a generic function.
Ideally, you'd like to be able to use compose on higher-order functions like the following:
Idea: you want to float out the free type variables into the result type for whatever doesn't get unified.
You want to build up the inferences:
You iterate on
A,B, andC, finding new "truths" about the relationships between these type variables. For example, you can see that:and then
But there are questions: how do you
Parameters type aliases
#26042
Method parameter inference
#23911