Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): allow setting unions in stores #1058

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

otonashixav
Copy link
Contributor

@otonashixav otonashixav commented Jun 14, 2022

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?

- This makes it so that:
```ts
const [store, setStore] = createStore([{ 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.

There are performance concerns with this implementation.
@coveralls
Copy link

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 Coverage Status
Change from base Build 2482635498: 0.0%
Covered Lines: 1252
Relevant Lines: 1335

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants