Power Tools: Typed Arrays & Union Types
9 min · TypeScript
Type your arrow functions, map over typed arrays, and narrow union types.
Enemy 1 of 5
You've already seen arrow functions written without types elsewhere, and typed functions using the function keyword. This is where the two meet: an arrow function can be typed just as fully as a regular one, with parameter types and a return type — (n: number): number => n * n.
TypeScript checks that the parameter and return types match wherever the arrow function is called, exactly as it would for a function written with the function keyword — the shorter arrow syntax doesn't cost you any type safety, it's purely a different way to write the same thing.
Stuck? Ask Rena
Your AI tutor that gives assistance.
Asking Rena in lessons is on Ultimate.