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

Working with function types #100

Open
jasonkuhrt opened this issue May 31, 2023 · 3 comments
Open

Working with function types #100

jasonkuhrt opened this issue May 31, 2023 · 3 comments

Comments

@jasonkuhrt
Copy link

Examples:

  • Remove a union member from the return type
  • add a union member to the return type
  • remove a paramter
  • add a paramter
  • map over the paramters
  • ...

Would this be in scope for this project?

@gvergnaud
Copy link
Owner

gvergnaud commented Jun 5, 2023

Maybe a few functions like Functions.MapArguments<Mapper> and Functions.MapReturnType<Mapper> could be added to support these use cases?

type DoStuff<Fn> = Pipe<Fn, [
  // Remove a union member from the return type
  Functions.MapReturnType<Union.Exclude<"a">>,
  // add a union member to the return type
  Functions.MapReturnType<Union.Append<"b">>,
  // remove a parameter
  Functions.MapArguments<Tuples.Filter<Boolean.Extends<number>>>,
  // add a parameter
  Functions.MapArguments<Tuples.Append<"1" | "2" | "3">>,
  // map over the parameters
  Functions.MapArguments<Tuples.Map<Strings.ToNumber>>,
]>

What do you think?

@markerikson
Copy link

Potentially useful, yeah.

Going back to the Reselect MergeParameters example I'd linked at https://github.com/reduxjs/reselect/blob/v4.1.5/src/types.ts#L100-L148 (and the updated version from Anders Hejlsberg at https://github.com/reduxjs/reselect/blob/b2a85eeac3312bb62ae3c26bb44d9aabd8641552/src/versionedTypes/ts47-mergeParameters.ts )... what might those look like with this style of typing?

@gvergnaud
Copy link
Owner

Added Functions.MapParameters and Functions.MapReturnType to the latest release! let me know what you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants