I have a function, which will either throw an error, or return a string. When put in a loop, TypeScript doesn't understand what's being returned. Am I missing something, or do I just have to ignore this line?
const MAX_RETRIES = 2;
function doSomething(): string {
let count = 0;
while (count < MAX_RETRIES) {
try {
// Do some other things
return "Hello World!" // Return the actual data
} catch (e) {
if (count == MAX_RETRIES) {
throw e
} else count++;
}
}
}