thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.39k stars 150 forks source link

MetaStream type should allow factory to return nullish value #305

Closed earthlyreason closed 3 years ago

earthlyreason commented 3 years ago

According to the docstring for metaStream:

If the function returns null/undefined, no further action will be taken

So shouldn't the factory type here

https://github.com/thi-ng/umbrella/blob/fe6cee7534b8534ee97aa52b159979dba6b90461/packages/rstream/src/metastream.ts#L108

allow nullish values:

    factory: Fn<A, Subscription<B, B> | null | undefined>;

Currently, usages like this

    metaStream((x: string | undefined) => x && reactive(x));

get an error like this

Argument of type '(x: string | undefined) => "" | rs.Stream<string> | undefined' is not assignable to parameter of type 'Fn<string | undefined, Subscription<string, string>>'.
  Type '"" | Stream<string> | undefined' is not assignable to type 'Subscription<string, string>'.
    Type 'undefined' is not assignable to type 'Subscription<string, string>'. [2345]
postspectacular commented 3 years ago

You're absolutely right, @gavinpc-mindgrub! Have updated the sigs and also switched to the more general ISubscription interface as return type (even though currently everything is pretty much a subclass of Subscription only)...

earthlyreason commented 3 years ago

Many thanks @postspectacular!