Cast from `Type | undefined`
Hi everyone.
I'm trying to show a data from Sanity CMS, using
createAsync
:
But the problem is, any way to cast dat()
to my Type
removing the Type | undefined
? Because currently the ProjectHeroSection
is complain because the data()
could be undefined
, but at this point I know that isn't undefined
.
Anyone can help me please?6 Replies
This is sort of just normal really. Typescript has no way to know that your
Show
component means that other calls to data()
will always have a value.
Since you know better, you can assert the value is non-null if you want to (with ! instead of ?):
but any way to assert the value to non-null for the entire component (inside the
Show
)?Sure. Show provides also a callback for children which provides the value of the truthy when condition. So you should remove the double “!!“:
There’s also a keyed prop for show which turns the callback value into a store like object.
See last example in the docs:
https://docs.solidjs.com/reference/components/show
Thanks and sorry for the noob questions
Your welcome.
No need to be sorry ☺️
keyed
property