Looking to simplify this code:
function checkIfExist(container?: string[]): boolean {
if (container) {
return container.indexOf("element") > -1
}
return false
}
...and I had the idea of using Optional Chaining for this purpose. However, it seems to not be working and there might be a misunderstanding on my end...
function checkIfExist(container?: string[]): boolean {
return container?.indexOf("element") > -1 // ERROR: Object is possibly 'undefined'. (2532)
}