crimx/observable-hooks

Inputs are inferred as an array, should be a tuple

OliverJAsh opened this issue · 3 comments

https://stackblitz.com/edit/rxjs-9ptyfz?devtoolsheight=60

I can raise a quick PR for this.

import { map } from "rxjs/operators";
import { useObservable } from "observable-hooks";

useObservable(
  inputs$ =>
    inputs$.pipe(
      map(
        inputs =>
          // Expected type: [number, string]
          // Actual type: (string | number)[]
          inputs
      )
    ),
  [1, "foo"]
);

Or perhaps we should recommend using const assertions?

import { map } from "rxjs/operators";
import { useObservable } from "observable-hooks";

useObservable(
  inputs$ =>
    inputs$.pipe(
      map(
        inputs =>
          // Expected + actual type: [number, string]
          inputs
      )
    ),
  [1, "foo"] as const
);

Note: this is not a problem in rxjs-hooks because of the RestrictArray trick they use. We could also do that…

https://github.com/LeetCode-OpenSource/rxjs-hooks/blob/89c4b89265b410a7c46cd5060629637e32c5ce8c/src/use-observable.ts#L23

crimx commented

Or perhaps we should recommend using const assertions?

Yes, we currently use as const as workaround.

because of the RestrictArray trick they use. We could also do that…

Sure, if it works.

I'm exploring different ways we could achieve this: https://twitter.com/OliverJAsh/status/1299318916272074753.