mirror of https://github.com/sveltejs/svelte
[fix] relax store derived function signature (#6509)
With this fix, doing ``` const stores= [writable(0), writable(1)] derived(stores, ([a,b,c]) => {}); ``` works without type errors. The propblem with the previous type signature was that it's too strict for TypeScript's suboptimal inference of the value `stores` in that example, which is `Array<Readable<any>>`, which does not convey the info "at least one element", which the old Stores signature required. Runtime-wise, it's no problem passing an empty array to derived. The new signature is only appended to, not replaced, because the old signature is able to correctly infer the values of each array entry: For `derived([writable(0), writable('foo')], ([a, b]) => {});` the parameters `a` and `b` are correctly inferred as `number` and `string`. If the type would be changed to `type Stores = Readable<any> | Array<Readable<any>>` that would be no longer the case. Fixes #6178pull/6510/head
parent
6a7f3083a7
commit
ce43bd67c7
Loading…
Reference in new issue