简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM