Inputs are inferred as an array, should be a tuple
OliverJAsh opened this issue · 3 comments
OliverJAsh commented
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"]
);
OliverJAsh commented
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…
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.
OliverJAsh commented
I'm exploring different ways we could achieve this: https://twitter.com/OliverJAsh/status/1299318916272074753.