we're all familiar with the
tune?.image
type of null checks in Typescript optional chaining docs
but what's the best practice for checking this with an array value?
tune.images?[0]
will not work. I often use:
tune.images ? tune.images[0] : null
actually I think this is the better example:
tune.images.length
where tune?.images?.length
will fail.
the best alternate I've found is:
if (!tune.images || tune?.images?.length < 1) {
but it seems overly verbose. Better ideas?
tune.images?.[0]
, see optional chaining with expressionslength
seems to be the more problematic