this needs explicit type narrowing -
if (typeof result === "object" && !Array.isArray(result)) { if (result?.error) { log(result.error) } } else { if (Array.isArray(result)) { setData(result); } }