I'm attempting to contribute to a project and I've noticed a function declaration syntax that I don't understand, or at least I don't appreciate the value of it. Here is the syntax:
export const getRecordById: (number) => number| undefined = (id: number) => {
return id + 1 // not real logic
}
I interpret that as getRecordById
is declared as a function type that takes a single number
parameter and returns either a number
type or undefined
. It is assigned to a function with a number parameter named id
If I've got that right, I would write that function like this:
export function getRecordById(id: number): number| undefined {
return id + 1 // not real logic
}
My question is, what is the value in the more verbose and, to me, cryptic syntax in the first example? I suspect there IS a reason, but I don't understand or know it. What am I missing?