

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Function Type Syntax
incomplete
2: Inferred Return Types
incomplete
3: Void
incomplete
4: Function Types
incomplete
5: Type Alias
incomplete
6: Importing Types
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Functions themselves are values in JavaScript (and by extension, TypeScript), which means they must also have a type, right? You might think:
Oh, easy. They're probably some "
function" type.
Not so fast. Function types are much more specific than that. In TypeScript, a function's type includes information about its parameters and return value.
The syntax for a function type looks like this:
(param1: type1, param2: type2, ...) => returnType
For example, a function that takes two numbers and returns a number:
(a: number, b: number) => number;
and both of these functions are of that type:
const add = (a, b) => a + b;
const subtract = (a, b) => a - b;