Reputation: 6196
Why do we need to name the parameter types in the type annotation of functions?
let f: (a:number, b:number) => number;
Why is a
and b
required here?
Upvotes: 1
Views: 60
Reputation: 1690
This is a design decision to make the code more readable. Also parameters in "normal" functions also need a name. Let's take the example of you using a libary which includes arrow functions, what do you think is easier to use of the following two examples?
const getResult: (string, number?, number?) => queryObject;
or
const getResult: (id: string, startIndex?: number, endIndex?: number) => queryObject;
I hope this makes it clear to you
Upvotes: 2