While developing an application, I encountered an error that says: "not all code paths return a value". The error is specifically in the function named addValues, indicating that the function must return "Obj[] | undefined".
Here is the code snippet in question:
public addValues() {
const inputValue = document.getElementById('valor') as HTMLFormElement;
const inputNameValue =
document.getElementById('nome-valor') as HTMLFormElement;
const enterChecked = document.getElementById('entrada') as HTMLFormElement;
const leftChecked = document.getElementById('saida') as HTMLFormElement;
if (inputValue?.length && inputNameValue?.length && (enterChecked.checked || leftChecked.checked)) {
const list: Obj = {
id: Math.random(),
valor: +inputValue,
nomeValor: String(inputNameValue),
checked: enterChecked.checked ? enterChecked : leftChecked
}
if (this.valores == undefined) {
return undefined
}
return this.valores = [list]
}