solid
solid copied to clipboard
feat(types): allow setting unions in stores
Summary
This makes it so that:
const [store, setStore] = createStore<({ a: number } | { b: number })[]>([{ a: 1 }, { b: 2 }]);
setStore(0, "a", 1); // currently error, now ok
Which is potentially unsafe, but is already allowed if e.g. { b: 2 } was a NotWrappable instead. Note however that letting inference work will instead infer
({
a: number;
b?: undefined;
} | {
b: number;
a?: undefined;
})[]
which the setter has no issue with. However this is only applicable when the original array already contains all the types you intend it to hold.
There are performance concerns with this implementation.
How did you test this change?
Pull Request Test Coverage Report for Build 2492554255
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 89.013%
| Totals | |
|---|---|
| Change from base Build 2482635498: | 0.0% |
| Covered Lines: | 1252 |
| Relevant Lines: | 1335 |