Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Meeting Notes, 8/3/2018 #26951

Closed
DanielRosenwasser opened this issue Sep 6, 2018 · 0 comments
Closed

Design Meeting Notes, 8/3/2018 #26951

DanielRosenwasser opened this issue Sep 6, 2018 · 0 comments
Labels
Design Notes Notes from our design meetings

Comments

@DanielRosenwasser
Copy link
Member

Thoughts about unification

declare function compose<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:

    declare function compose<T, U, V>(a: (x: T) => U, b: (y: U) => V): (x: T) => V;
    declare function arrayToList<T>(x: Array<T>): List<T>;
    declare function box<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.

    • @gcnew came the closest to getting something that would work appropriately for TypeScript

You want to build up the inferences:

declare function compose<A, B, C>(a: (x: A) => B, b: (y: B) => C): (x: A) => C;
declare function arrayToList<T>(x: Array<T>): List<T>;
declare function box<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:

U = List<T>

and then

C = { value: List<T> }

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
type Parameters<T extends (...args: (infer U)) => any> = U;
  • Conclusion: we'll fix up the type an add it to the library.

Method parameter inference

#23911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Notes Notes from our design meetings
Projects
None yet
Development

No branches or pull requests

1 participant