#In ts, if a property of an object does not exist, how would I make it use the next value?

1 messages · Page 1 of 1 (latest)

grand summit
#

In js, something like this would have worked however in ts it complains that .name property does not exist on a type of channel (meaning channel may not always have a name).

console.log(`${channel?.name || 'default value'}`)
drifting kraken
#

"name" in channel ? channel.name : "default value"

#

if channel is nullable, then you have to check for that as well, channel && "name" in channel