cujojs / most

Ultra-high performance reactive programming
MIT License
3.49k stars 231 forks source link

Update typescript typings for .sample() #536

Open vlinder opened 4 years ago

vlinder commented 4 years ago

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

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]> };
vlinder commented 3 years ago

Ping? :)