Typesafe way to render conditionally based on whether array has zero, one or many elements?
Given an array with one or more elements, the idea is to display different UIs. With React, this can be done in a typesafe way by returning different JSX after an
How can the same be achieved with Solid? Seems that
When adding
although this seems overly verbose, and I feel uneasy about using
if check,How can the same be achieved with Solid? Seems that
<Switch /> / <Match /> was a good place to start, although the where's boolean check doesn't perform type narrowing, so the typecheck fails: the array could be empty and accessing the first element could return undefined. When adding
<Show /> to the mix, the type safety can be improved,although this seems overly verbose, and I feel uneasy about using
<Show> just for its non-null assertion. Are there better options?