After completing the development of a new method for a bug I encountered, I noticed something interesting. Despite the fact that there is a potential scenario where the function may not return anything, the compiler did not flag any errors. It got me thinking - why does the compiler stay silent in this case, but raises an issue when using if (false)
?
I'm particularly curious about what happens if the condition
if (data && data.json().length)
evaluates to false. Does the function still return a value under such circumstances?
private async getData(items: any[]): Promise<number> {
for(const item of items) {
let data = await item.promise;
if (data && data.json().length) {
return data.json().findIndex(d => d.fqdn);
}
}
}
Your insights would be greatly appreciated.