Closed
Description
π Search Terms
"typescript function that throws", "typescript function that always throws"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.7 + 5.1
β― Playground Link
π» Code
function consoleErrorAndThrow_1(errorMessage: string): never { // <--- Normal function
console.error(errorMessage);
throw new Error(errorMessage);
}
const wrapperFunction_1 = (someVar: number) => {
if (someVar < 5) {
return someVar;
} else {
consoleErrorAndThrow_1(`Error was found!`);
}
};
const consoleErrorAndThrow_2 = (errorMessage: string): never => { // <--- Arrow function
console.error(errorMessage);
throw new Error(errorMessage);
}
const wrapperFunction_2 = (someVar: number) => { // Not all code paths return a value. (7030)
if (someVar < 5) {
return someVar;
} else {
consoleErrorAndThrow_2(`Error was found!`);
}
};
π Actual behavior
Get error Not all code paths return a value. (7030)
π Expected behavior
No error