at the end of the form chapter, how can manage the add expense with no arrow function? I mean I would like to have a separate function to save new expense, if I try something like this:
function addExpense (newExpense) {
setExpenses([…expenses, { …newExpense, id: expenses.length + 1 }]);
ts show a warning “Parameter ‘newExpense’ implicitly has an ‘any’ type.”, works but this warning ???
You need to give your newExpense parameter an explicit type:
function addExpense (newExpense: Expense)
Benefit: You get Intellisense help and type checks. Without the type the implicit type is any and the function behaves like JavaScript: In case you misspell something or perform invalid operations your function fails at run time instead of compile time.