Why is storageSignal possibly null?
I am having trouble understanding why TypeScript thinks that this storageSignal
theme
can be null:
I am setting the initial value to a ternary and explicitly typing the signal, but alas, TS says that theme
can be "dark" | "light" | null
.
What am I missing here?11 Replies
looks like it's part of the type signature of
createStorageSignal
.
It seems like the result can be null
if the api
doesn't exist:
api
: an array of or a single localStorage-like storage API; default will be localStorage if it exists; an empty array or no API will not throw an error, but only ever get null and not actually persist anything
Thank you! I guess the pop-up tooltip in VSCode didn’t show me the same view because I was trying to override the Accessor to only return T and never null
I ended up making an adapter function to handle the null
The current version is closer to Storage than to solid.
I intend to deprecate the whole API and instead add a makePersisted primitive that will persist signals and stores alike.
GitHub
Storage rewrite by atk · Pull Request #458 · solidjs-community/soli...
The storage package was needlessly complex, large and led to frequent misunderstandings from developers who expected it to work like a store. I have learned from my mistakes and deprecated the old ...
Update: just merged it. I really hope that simplifies things.
That appears to make things much simpler! Will this be released or do I need to pull it down another way? (If so, how?)
It should be released today.
Okay, just triggered the release. It should be on npm in the next minutes.
At least once this action is complete: https://github.com/solidjs-community/solid-primitives/actions/runs/5445261864
GitHub
Version Packages (#467) · solidjs-community/solid-primitives@1c1f16e
A library of high-quality primitives that extend SolidJS reactivity. - Version Packages (#467) · solidjs-community/solid-primitives@1c1f16e
@lexlohr This is brilliant... so much clearer and more intuitive
Thanks. I'm glad you like it. It's the result of a hard lesson learned.
and I could just type the signal to avoid any nulls