- Modern JavaScript Web Development Cookbook
- Federico Kereki
- 70字
- 2021-07-02 14:49:55
Defining types for arrow functions
Finally, let's see how types would be defined for arrow functions. We can have a couple more implementations of the toString() function we saw earlier in the Basic types in Flow section:
// Source file: src/types_basic.js
const toString2 = (x: number): string => {
return x + "";
};
type numberToString = number => string;
const toString3: numberToString = (x: number) => String(x);