Skip to content

Better type safety possible for accumCombine? #65

@deklanw

Description

@deklanw

I noticed while looking at TodoMVC that the following isn't fully typesafe,

  return accumCombine(
    [
      [prependItemS, (item, list) => [item].concat(list)],
      [
        removeKeyListS,
        (keys, list) => list.filter((item) => !includes(itemToKey(item), keys))
      ]
    ],
    initial
  );

where prependItemS: Stream<A> and removeKeyListS: Stream<B[]>, but item: any and keys: any.

I looked at the types,

export declare function accumFrom<A, B>(f: (a: A, b: B) => B, initial: B, source: Stream<A>): Behavior<Behavior<B>>;
export declare function accum<A, B>(f: (a: A, b: B) => B, initial: B, source: Stream<A>): Now<Behavior<B>>;
export declare type AccumPair<A> = [Stream<any>, (a: any, b: A) => A];
export declare function accumCombineFrom<B>(pairs: AccumPair<B>[], initial: B): Behavior<Behavior<B>>;
export declare function accumCombine<B>(pairs: AccumPair<B>[], initial: B): Now<Behavior<B>>;

I see that if you do this

export declare type AccumPair<A, C> = [Stream<C>, (a: C, b: A) => A];

It won't work because C will get bound once to the first element of the first element of pairs.

Is rank-n polymorphism what is needed here? I've read about it a bit. Does TS support it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions