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

Update typescript typings for .sample() #536

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vlinder
Copy link

@vlinder vlinder commented Apr 22, 2020

Summary

Update typescript types to support the case of one value$ argument for .sample(). It is a bit unclear in the documentation that this is supported as well but .sampleWith() hints about it:

image

Todo

  • Unit tests for new or changed APIs and/or functionality
    No new functionality..
  • Documentation, including examples
    Just a simple change of wording.

Mapped types instead?

Would it be preferable to change to use mapped types where possible for all the instances where we have overloaded types because of variable number of arguments? Then we could support an arbitrary number of arguments without having to resort to overloads.

Mapped types has been around since TS 2.1. Will possibly need the improvements to rest/spread types that came later though (3.2). might be unrelated to my point

Example implementation

sample<B extends unknown[], R>(
  fn: (...b: B) => R,
  ...b: { [T in keyof B]: Stream<B[T]> }
): Stream<R>;

Could also have a helper type to box elements in all the functions that will need to implement this:

type StreamBoxed<T> = { [K in keyof T]: Stream<T[K]> };

Updating docs to be more clear about .sample accepting one streams as values argument as well.
@vlinder
Copy link
Author

vlinder commented Aug 26, 2020

Ping? :)

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

Successfully merging this pull request may close these issues.

None yet

1 participant