Typing functions
When declaring a function we can type both the arguments and the return value:
Reusable function type
Let's say the above function implements a very common pattern in out app: do some calculation with two numbers.
We can create a function type:
The void
type
void
typeOne type is particularly useful with functions is void
: to signify that nothing will be returned from the function:
Optional and default arguments
Function arguments can be marked as optional using the ?
sign
We can also provide a default value; any argument with a default value will automatically be marked as optional.
Resources
Last updated