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

Equivalent of Flow's $ObjMap #20352

Closed
bcherny opened this issue Nov 29, 2017 · 3 comments
Closed

Equivalent of Flow's $ObjMap #20352

bcherny opened this issue Nov 29, 2017 · 3 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@bcherny
Copy link

bcherny commented Nov 29, 2017

https://flow.org/en/docs/types/utilities/#toc-objmap

From Flow's docs:

ObjMap<T, F> takes an object type T, and a function type F, and returns the object type obtained by mapping the type of each value in the object with the provided function type F. In other words, $ObjMap will call (at the type level) the given function type F for every property value type in T, and return the resulting object type from those calls.

We could probably implement this if/once #6606 is implemented:

type ObjMap<T extends object, F extends Function> = {
  [K in T]: typeof F(T[K])
}

Tracking this in a separate issue in case someone searches for TypeScript's equivalent of $ObjMap. Feel free to close this and fold into 6606 if you prefer!

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Nov 29, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Nov 29, 2017

related to #6606

@RyanCavanaugh
Copy link
Member

We can do this with ReturnType now (minus overloading which I think needs to just switch to conditional types at this point for good type system support)

@lazytype
Copy link

@RyanCavanaugh Can we keep #40179 open for the overloading case? (preemptively asking before it's potentially closed for the same reason as this one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants