Thomas
Thomas

Reputation: 6196

Why does typescript require names in function types?

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

Answers (1)

Zer0
Zer0

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

Related Questions