Module lessons (1/2)
Typical functions
Note optional parameters, default values, rest params, reusable type signatures, and void.
What you'll learn in this lesson
- Note mandatory, optional (
lastName?: string) and default value (exponent: number = 2) parameters. - Extract and reuse function signatures via
typealias ((a: number, b: number) => number). - Model safe callbacks with
: voidand recognize whyvoidin callback returns also accepts return-ignored functions. - Use typed rest parameters (
...values: number[]) and understand overloads with respect to unions.
Overview
Functions are the behavioral units of every TypeScript codebase. Typing its parameters and return means transforming the caller into an ally automatically controlled by the IDE.
A parameter marked with ? must follow all the mandatory parameters and takes type T | undefined. A parameter with a default value (rate: number = 0.22) automatically infers the type and does not require ?.
Sections covered in this lesson
- 1Optional parameters, default and rest
- 2Function Type Expressions and Callbacks
: void - 3Guided practice
- 4Check for understanding
Unlock "Typical functions" and the full Course TypeScript curriculum
Note optional parameters, default values, rest params, reusable type signatures, and void.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course TypeScript plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.