Skip to content

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

Closed
otonashixav wants to merge 1 commit intosolidjs:mainfrom
otonashixav:feat-types-store-setter-union-access
Closed

feat(types): allow setting unions in stores#1058
otonashixav wants to merge 1 commit intosolidjs:mainfrom
otonashixav:feat-types-store-setter-union-access

Conversation

@otonashixav
Copy link
Copy Markdown
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
Copy Markdown

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

@ryansolid
Copy link
Copy Markdown
Member

I'm not sure why we never merged this. But given the move in 2.0 to make path second class. I'm closing old PRs we aren't likely to address.

@ryansolid ryansolid closed this Mar 4, 2026
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.

3 participants