What this function should return depends on what the calling code expects. Using optional chaining will prevent the code from throwing an error, but will instead return undefined, which may not be what the calling code expects.
You need to handle this by either returning a default value in case your first expression doesn't return anything, or changing the calling code so that it can appropriately deal with a return value such as undefined.
You can return a default value in case your first expression evaluates to undefined by using the nullish coalescing operator:
getState(dc) {
const defaultValue = ''; // whatever your default value is
return data.channels[channelId]?.channelStatus?.find(item =>{item.dc === dc}) ?? defaultValue;
}
channelStatus?.findjs function getState(dc) { let state = null; if (data) { if(data.channels) { if(data.channels[channelId]) { if(data.channels[channelId].channelStatus) { return data.channels[channelId]?.channelStatus.find(item =>{item.dc === dc}) } } } } }statewhenchannelStatusis null?