Skip to content

Equivalent of Flow's $ObjMap #20352

Description

@bcherny

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!

Activity

  1. mhegazy commented on Nov 29, 2017

    @mhegazy
    Contributor

    related to #6606

  2. RyanCavanaugh commented on Jan 14, 2021

    @RyanCavanaugh
    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)

  3. lazytype commented on Jan 14, 2021

    @lazytype

    Ryan Cavanaugh (@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions