&& in <Show> when condition and typescript?
Is this possible or do I need three nested show components. I don't think I can use the typical
{data => {data()}}
format inside show in this case19 Replies
I had something similar, and this is what I went with
I'm not sure if the other way would work, but I found this much cleaner to read.
Put selectedDate last
And make the other expressions explicit about what you're checking for
Then you can use the callback form
The problem is that the when prob is expecting a boolean and && will get you the first of its operators that is not falsy, so you are using a date or number here when a boolean is expected. Just wrap it in
!!(...)
.Do you mean like this?
That should solve the type issue.
And use "!" after the signal.
Or you create a getter or createMemo to narrow the types and use this in the Show instead to get correct narrowed types for all props like this
https://playground.solidjs.com/anonymous/05949c3d-6a4b-4686-8d60-64b135bf48ef
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Do you mean using ! When accessing signal to make element inside show parent? Doesn't that remove the benefits of typescript
The benefit here is to test something that typescript cannot possibly discern, but you already know is true: that if the condition inside the when-prop is true, the value is present. So it is perfectly OK to use the exclamation mark in that case. Just don't go over board with it.
More like this
or do this to get type inference correctly:
Is n really an accessor in this case?
According to the docs, it isn't.
It is an accessor
Then we need to fix https://docs.solidjs.com/reference/components/show
It seems you are indeed correct. We need to fix the docs!
It is an accessor unless you set the keyed prop to true. Then it’s “like” a store. So the docs are correct.
The docs only show the keyed case. Maybe it makes sense to add an example with a callback without keyed.
I think we should at least add a line to document this behavior.
GitHub
fix: unkeyed show argument by atk · Pull Request #922 · solidjs/sol...
I have read the Contribution guide
This PR references an issue (except for typos, broken links, or other minor problems)
Description(required)
The reference for Show does not document the unkeyed...
I usually prefer code examples over text. The PR is also adds a second generic for the Show component that's unused. I think that should be corrected.
Right, I wanted to extend the type to be more precise, that's a leftover.
GitHub
feat: improve show docs by atk · Pull Request #924 · solidjs/solid-...
example for unkeyed show
remove stray leftover generic
I have read the Contribution guide
This PR references an issue (except for typos, broken links, or other minor problems)
Description(req...